summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-lua-runtime
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-11-15 19:49:05 +0100
committerJo-Philipp Wich <jo@mein.io>2022-11-15 19:49:05 +0100
commita1ee78fa696e13ad4e19c0252eb345500d4ab3ee (patch)
treecf18deae99ecf74aefa84f44d912cf8c1f419067 /modules/luci-lua-runtime
parent2be01cbfcb34746d9713173a60c3f8a69c554a68 (diff)
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>
Diffstat (limited to 'modules/luci-lua-runtime')
-rw-r--r--modules/luci-lua-runtime/luasrc/dispatcher.lua10
1 files changed, 4 insertions, 6 deletions
diff --git a/modules/luci-lua-runtime/luasrc/dispatcher.lua b/modules/luci-lua-runtime/luasrc/dispatcher.lua
index 5c349114c4..f97e84a69b 100644
--- a/modules/luci-lua-runtime/luasrc/dispatcher.lua
+++ b/modules/luci-lua-runtime/luasrc/dispatcher.lua
@@ -6,16 +6,14 @@ module("luci.dispatcher", package.seeall)
local http = _G.L.http
-context = setmetatable({
- request = _G.L.ctx.request_path;
- requested = _G.L.node;
- dispatched = _G.L.node;
-}, {
+context = setmetatable({}, {
__index = function(t, k)
- if k == "requestpath" then
+ if k == "request" or k == "requestpath" then
return _G.L.ctx.request_path
elseif k == "requestargs" then
return _G.L.ctx.request_args
+ elseif k == "requested" or k == "dispatched" then
+ return _G.L.node
else
return _G.L.ctx[k]
end