Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,14 @@ not_globals = {
ignore = {
"6.", -- ignore whitespace warnings
}


globals = {
ngx = {
req = {
set_uri_args = {
read_only = false
}
}
}
}
13 changes: 13 additions & 0 deletions lualib/resty/kong/var.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local C = ffi.C
local ffi_new = ffi.new
local ffi_str = ffi.string
local var = ngx.var
local req = ngx.req
local type = type
local error = error
local assert = assert
Expand Down Expand Up @@ -150,6 +151,16 @@ local function var_set_by_index(index, value)
end


local function patch_functions()
local orig_set_uri_args = req.set_uri_args

req.set_uri_args = function(...)
variable_index.args = nil
return orig_set_uri_args(...)
end
end


local function patch_metatable()
if get_phase() ~= "init" then
error("patch_metatable can only be called in init phase")
Expand Down Expand Up @@ -184,6 +195,8 @@ local function patch_metatable()

return orig_set(self, name, value)
end

patch_functions()
end


Expand Down
35 changes: 34 additions & 1 deletion t/005-indexed-var-openresty-suites.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use Test::Nginx::Socket::Lua;

repeat_each(2);

plan tests => repeat_each() * (blocks() * 2 + 9 + 4);
plan tests => repeat_each() * (blocks() * 2 + 9 + 4 + 3);

#no_diff();
#no_long_string();
Expand Down Expand Up @@ -359,3 +359,36 @@ variable not changeable
["GET /balancer?port=8091", "GET /balancer?port=8092"]
--- response_body eval
["this is backend peer 8091", "this is backend peer 8092"]

=== TEST 13: patch metatable does not invalidate function req.set_uri_args
--- http_config
lua_package_path "../lua-resty-core/lib/?.lua;lualib/?.lua;;";
# this is not required, but set explictly in tests
lua_kong_load_var_index $args;

init_by_lua_block {
local var = require "resty.kong.var"
var.patch_metatable()
}

--- config
set $args 'foo=bar';

location /t {
content_by_lua_block {
local a = ngx.var.args
ngx.req.set_uri_args(a .. "&added=yes")
ngx.say(ngx.var.args)
}
}

--- request
GET /t
--- response_body_like
foo=bar&added=yes

--- error_code: 200
--- no_error_log
[error]
[crit]
[alert]