Skip to content

Commit

Permalink
fix(ctx) use global ctx where request is unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
fffonion committed Apr 13, 2022
1 parent e076b27 commit e3590cf
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/resty/openssl/ctx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,30 @@ local function free(request_context_only)
return true
end

local test_request

do

local ok, exdata = pcall(require, "thread.exdata")
if ok and exdata then
test_request = function()
local r = exdata()
if r ~= nil then
return not not r
end
end

else
local getfenv = getfenv

function test_request()
return not not getfenv(0).__ngx_req
end
end
end

return {
new = new,
free = free,
get_libctx = function() return ngx.ctx.ossl_lib_ctx or ossl_lib_ctx end,
get_libctx = function() return test_request() and ngx.ctx.ossl_lib_ctx or ossl_lib_ctx end,
}

0 comments on commit e3590cf

Please sign in to comment.