File tree Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ local C = ffi.C
6
6
local ffi_new = ffi .new
7
7
local ffi_str = ffi .string
8
8
local var = ngx .var
9
+ local req = ngx .req
9
10
local type = type
10
11
local error = error
11
12
local assert = assert
@@ -150,6 +151,16 @@ local function var_set_by_index(index, value)
150
151
end
151
152
152
153
154
+ local function patch_functions ()
155
+ local orig_set_uri_args = req .set_uri_args
156
+
157
+ req .set_uri_args = function (...)
158
+ variable_index .args = nil
159
+ return orig_set_uri_args (... )
160
+ end
161
+ end
162
+
163
+
153
164
local function patch_metatable ()
154
165
if get_phase () ~= " init" then
155
166
error (" patch_metatable can only be called in init phase" )
@@ -184,6 +195,8 @@ local function patch_metatable()
184
195
185
196
return orig_set (self , name , value )
186
197
end
198
+
199
+ patch_functions ()
187
200
end
188
201
189
202
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ use Test::Nginx::Socket::Lua;
9
9
10
10
repeat_each(2 );
11
11
12
- plan tests => repeat_each() * (blocks() * 2 + 9 + 4 );
12
+ plan tests => repeat_each() * (blocks() * 2 + 9 + 4 + 3 );
13
13
14
14
# no_diff();
15
15
# no_long_string();
@@ -359,3 +359,36 @@ variable not changeable
359
359
["GET /balancer?port=8091" , "GET /balancer?port=8092" ]
360
360
--- response_body eval
361
361
["this is backend peer 8091" , "this is backend peer 8092" ]
362
+
363
+ === TEST 13: patch metatable does not invalidate function req. set_uri_args
364
+ --- http_config
365
+ lua_package_path "../lua-resty-core/lib/?.lua;lualib/?.lua;;" ;
366
+ # this is not required, but set explictly in tests
367
+ lua_kong_load_var_index $ args ;
368
+
369
+ init_by_lua_block {
370
+ local var = require " resty.kong.var"
371
+ var. patch_metatable()
372
+ }
373
+
374
+ --- config
375
+ set $ args 'foo=bar' ;
376
+
377
+ location /t {
378
+ content_by_lua_block {
379
+ local a = ngx. var. args
380
+ ngx. req. set_uri_args(a .. " & added =yes" )
381
+ ngx. say (ngx. var. args)
382
+ }
383
+ }
384
+
385
+ -- - request
386
+ GET / t
387
+ -- - response_body_like
388
+ foo= bar& added = yes
389
+
390
+ -- - error_code: 200
391
+ -- - no_error_log
392
+ [error]
393
+ [crit]
394
+ [alert]
You can’t perform that action at this time.
0 commit comments