This is an automated email from the ASF dual-hosted git repository.

AlinsRan 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 a546e85594 fix(router): keep the query string when 
normalize_uri_like_servlet is on (#13982)
a546e85594 is described below

commit a546e855940bcdf4d97b04439bb228b944d6ded5
Author: AlinsRan <[email protected]>
AuthorDate: Mon Oct 26 14:32:49 2026 +0800

    fix(router): keep the query string when normalize_uri_like_servlet is on 
(#13982)
---
 apisix/init.lua                 | 17 ++++++++++++++---
 t/router/servlet-upstream-uri.t | 14 +++++++++++++-
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/apisix/init.lua b/apisix/init.lua
index 0fb6cceb61..7f8a00609b 100644
--- a/apisix/init.lua
+++ b/apisix/init.lua
@@ -553,6 +553,19 @@ local function normalize_uri_like_servlet(uri)
 end
 
 
+-- Forward the original path so servlet upstreams can consume params after ';'.
+-- URI-encode it before proxying to keep delimiters as path data.
+--
+-- Setting $upstream_uri at all turns off the "empty proxy_pass URI" 
passthrough
+-- that otherwise hands the client's request line -- query string included -- 
to
+-- the upstream unchanged, so the query string has to be re-appended here.
+local function set_servlet_upstream_uri(api_ctx, uri)
+    api_ctx.var.upstream_uri = core.utils.uri_safe_encode(uri)
+                               .. (api_ctx.var.is_args or "")
+                               .. (api_ctx.var.args or "")
+end
+
+
 -- Percent-decode every %XX in the path. When keep_slash is true, an encoded
 -- slash (%2F/%2f) is left as the literal text "%2F" instead of being turned
 -- into a real path separator -- Nginx decodes it into '/' in $uri, which makes
@@ -881,9 +894,7 @@ function _M.http_access_phase()
             end
 
             api_ctx.var.uri = new_uri
-            -- Forward the original path so servlet upstreams can consume 
params
-            -- after ';'. URI-encode it before proxying to keep delimiters as 
path data.
-            api_ctx.var.upstream_uri = core.utils.uri_safe_encode(uri)
+            set_servlet_upstream_uri(api_ctx, uri)
         end
     end
 
diff --git a/t/router/servlet-upstream-uri.t b/t/router/servlet-upstream-uri.t
index a816cd06e4..0a5b3efe06 100644
--- a/t/router/servlet-upstream-uri.t
+++ b/t/router/servlet-upstream-uri.t
@@ -143,7 +143,19 @@ 
qr/^path-handler\nroute-marker=[a-f]{6}\nrequest-uri=\/anything%3Fprobe;jsession
 
 
 
-=== TEST 4: delete routes
+=== TEST 4: query string is forwarded alongside the servlet path
+--- request
+GET /anything/sub;jsessionid=x?foo=bar&baz=1
+--- more_headers
+Host: servlet-uri.test
+--- response_body_like eval
+qr/^path-handler\nroute-marker=[a-f]{6}\nrequest-uri=\/anything\/sub;jsessionid=x\?foo=bar&baz=1\n$/
+--- no_error_log
+[error]
+
+
+
+=== TEST 5: delete routes
 --- config
     location /t {
         content_by_lua_block {

Reply via email to