Skip to content
Open
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
17 changes: 14 additions & 3 deletions apisix/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,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
Expand Down Expand Up @@ -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

Expand Down
14 changes: 13 additions & 1 deletion t/router/servlet-upstream-uri.t
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading