luci-lua-runtime: proxy all dispatcher context property accesses
The ucode side dispatcher environment might not be fully populated yet when the emulated Lua dispatcher is loaded, leading to `context.requested` and some other properties to be `nil`. Expose all properties through metatable `__index` lookups instead to ensure that the Lua side dispatcher always sees the latest values. Fixes: #6100 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
2be01cbfcb
commit
a1ee78fa69
1 changed files with 4 additions and 6 deletions
|
@ -6,16 +6,14 @@ module("luci.dispatcher", package.seeall)
|
||||||
|
|
||||||
local http = _G.L.http
|
local http = _G.L.http
|
||||||
|
|
||||||
context = setmetatable({
|
context = setmetatable({}, {
|
||||||
request = _G.L.ctx.request_path;
|
|
||||||
requested = _G.L.node;
|
|
||||||
dispatched = _G.L.node;
|
|
||||||
}, {
|
|
||||||
__index = function(t, k)
|
__index = function(t, k)
|
||||||
if k == "requestpath" then
|
if k == "request" or k == "requestpath" then
|
||||||
return _G.L.ctx.request_path
|
return _G.L.ctx.request_path
|
||||||
elseif k == "requestargs" then
|
elseif k == "requestargs" then
|
||||||
return _G.L.ctx.request_args
|
return _G.L.ctx.request_args
|
||||||
|
elseif k == "requested" or k == "dispatched" then
|
||||||
|
return _G.L.node
|
||||||
else
|
else
|
||||||
return _G.L.ctx[k]
|
return _G.L.ctx[k]
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue