-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
need to share context between internal redirect (openresty/lua-nginx-module#1057) but then the policies have total control over generating the content so they can use cosockets / files / upstream / generate content please note this is higly experimental and should not be merged to master yet
- Loading branch information
Showing
6 changed files
with
102 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
local ffi = require 'ffi' | ||
local debug = require 'debug' | ||
local base = require "resty.core.base" | ||
local misc = require "resty.core.misc" | ||
|
||
|
||
local registry = debug.getregistry() | ||
local new_tab = base.new_tab | ||
local ref_in_table = base.ref_in_table | ||
local getfenv = getfenv | ||
local C = ffi.C | ||
local FFI_NO_REQ_CTX = base.FFI_NO_REQ_CTX | ||
local FFI_OK = base.FFI_OK | ||
local error = error | ||
|
||
|
||
local _M = { | ||
|
||
} | ||
|
||
local mt = {} | ||
|
||
setmetatable(_M, mt) | ||
|
||
local exec = ngx.exec | ||
|
||
function _M.ctx_ref() | ||
local r = getfenv(0).__ngx_req | ||
|
||
if not r then | ||
return error("no request found") | ||
end | ||
|
||
local ctx = ngx.ctx | ||
local ctx_ref = C.ngx_http_lua_ffi_get_ctx_ref(r) | ||
if ctx_ref == FFI_NO_REQ_CTX then | ||
return error("no request ctx found") | ||
end | ||
|
||
local ctxs = registry.ngx_lua_ctx_tables | ||
-- TODO: why they are not equal? | ||
if ctx_ref == ref_in_table(ctxs, ctx) then | ||
return ctx_ref | ||
end | ||
|
||
return ctx_ref | ||
end | ||
|
||
function _M.ctx(ref) | ||
local r = getfenv(0).__ngx_req | ||
|
||
if not r then | ||
return error("no request found") | ||
end | ||
|
||
local ctx_ref = tonumber(ref) | ||
if not ctx_ref then | ||
return | ||
end | ||
|
||
if C.ngx_http_lua_ffi_set_ctx_ref(r, ctx_ref) ~= FFI_OK then | ||
return nil | ||
end | ||
|
||
return true | ||
end | ||
|
||
return _M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters