This is an automated email from the ASF dual-hosted git repository.
shreemaanabhishek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 78d91d8b5 fix: preserve uri args if path has not been modified (#13080)
78d91d8b5 is described below
commit 78d91d8b5d3ec2e40fe1be6c801cefa40772a97b
Author: Shreemaan Abhishek <[email protected]>
AuthorDate: Wed Mar 11 10:48:39 2026 +0545
fix: preserve uri args if path has not been modified (#13080)
---
apisix/plugins/ext-plugin/init.lua | 6 +--
t/lib/ext-plugin.lua | 7 ++++
t/plugin/ext-plugin/http-req-call.t | 74 +++++++++++++++++++++++++++++++++++++
3 files changed, 84 insertions(+), 3 deletions(-)
diff --git a/apisix/plugins/ext-plugin/init.lua
b/apisix/plugins/ext-plugin/init.lua
index 2631afd36..482ed0100 100644
--- a/apisix/plugins/ext-plugin/init.lua
+++ b/apisix/plugins/ext-plugin/init.lua
@@ -706,10 +706,10 @@ local rpc_handlers = {
end
core.request.set_uri_args(ctx, args)
+ end
- if path then
- var.upstream_uri = path .. '?' .. var.args
- end
+ if path then
+ var.upstream_uri = path .. (var.is_args or '') .. (var.args or
'')
end
end
diff --git a/t/lib/ext-plugin.lua b/t/lib/ext-plugin.lua
index 0ebf7192b..e0998b7a8 100644
--- a/t/lib/ext-plugin.lua
+++ b/t/lib/ext-plugin.lua
@@ -399,6 +399,13 @@ function _M.go(case)
local action = http_req_call_rewrite.End(builder)
build_action(action, http_req_call_action.Rewrite)
+ elseif case.rewrite_path_only then
+ local path = builder:CreateString("/plugin_proxy_rewrite_args")
+ http_req_call_rewrite.Start(builder)
+ http_req_call_rewrite.AddPath(builder, path)
+ local action = http_req_call_rewrite.End(builder)
+ build_action(action, http_req_call_action.Rewrite)
+
elseif case.rewrite_bad_path == true then
local path = builder:CreateString("/plugin_proxy_rewrite_args?a=2")
http_req_call_rewrite.Start(builder)
diff --git a/t/plugin/ext-plugin/http-req-call.t
b/t/plugin/ext-plugin/http-req-call.t
index 782dfa05c..4248695d0 100644
--- a/t/plugin/ext-plugin/http-req-call.t
+++ b/t/plugin/ext-plugin/http-req-call.t
@@ -807,3 +807,77 @@ cat
}
--- response_body
abc
+
+
+
+=== TEST 29: rewrite path only (preserve original query args)
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin")
+
+ local code, message, res = t.test('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "uri": "/hello",
+ "plugins": {
+ "ext-plugin-pre-req": {
+ }
+ },
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1980": 1
+ },
+ "type": "roundrobin"
+ }
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ ngx.say(message)
+ }
+ }
+--- response_body
+passed
+
+
+
+=== TEST 30: hit (original query args should be preserved when only path is
rewritten)
+--- request
+GET /hello?c=foo&d=bar
+--- extra_stream_config
+ server {
+ listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
+
+ content_by_lua_block {
+ local ext = require("lib.ext-plugin")
+ ext.go({rewrite_path_only = true})
+ }
+ }
+--- response_body
+uri: /plugin_proxy_rewrite_args
+c: foo
+d: bar
+
+
+
+=== TEST 31: hit (when no uri args are passed, there are no failures)
+--- request
+GET /hello
+--- extra_stream_config
+ server {
+ listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
+
+ content_by_lua_block {
+ local ext = require("lib.ext-plugin")
+ ext.go({rewrite_path_only = true})
+ }
+ }
+--- response_body
+uri: /plugin_proxy_rewrite_args