Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(radixtree_host_uri): correct matched path #5104

Merged
merged 1 commit into from
Sep 21, 2021
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
5 changes: 5 additions & 0 deletions apisix/http/router/radixtree_host_uri.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ local function push_host_router(route, host_routes, only_uri_routes)
api_ctx.matched_params = nil
api_ctx.matched_route = route
api_ctx.curr_req_matched = match_opts.matched
api_ctx.real_curr_req_matched_path = match_opts.matched._path
end
}

Expand Down Expand Up @@ -162,6 +163,10 @@ function _M.match(api_ctx)
local host_uri = api_ctx.var.host
local ok = host_router:dispatch(host_uri:reverse(), match_opts, api_ctx, match_opts)
if ok then
if api_ctx.real_curr_req_matched_path then
api_ctx.curr_req_matched._path = api_ctx.real_curr_req_matched_path
api_ctx.real_curr_req_matched_path = nil
end
return true
end
end
Expand Down
108 changes: 108 additions & 0 deletions t/router/radixtree-host-uri3.t
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,111 @@ hello world
404
404
hello world



=== TEST 2: check matched._path
--- config
location /t {
content_by_lua_block {
local http = require "resty.http"
local uri = "http://127.0.0.1:" .. ngx.var.server_port
.. "/hello"
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"hosts": ["foo.com"],
"plugins": {
"serverless-post-function": {
"functions" : ["return function(conf, ctx)
ngx.log(ngx.WARN, 'matched uri: ', ctx.curr_req_matched._path);
end"]
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
}]]
)

if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
ngx.say(body)
}
}
--- response_body
passed



=== TEST 3: hit, plain path
--- request
GET /hello
--- more_headers
Host: foo.com
--- grep_error_log eval
qr/matched uri: \/\w+/
--- grep_error_log_out
matched uri: /hello



=== TEST 4: check matched._path, wildcard
--- config
location /t {
content_by_lua_block {
local http = require "resty.http"
local uri = "http://127.0.0.1:" .. ngx.var.server_port
.. "/hello"
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"hosts": ["foo.com"],
"plugins": {
"serverless-post-function": {
"functions" : ["return function(conf, ctx)
ngx.log(ngx.WARN, 'matched uri: ', ctx.curr_req_matched._path);
end"]
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/*"
}]]
)

if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
ngx.say(body)
}
}
--- response_body
passed



=== TEST 5: hit
--- request
GET /hello
--- more_headers
Host: foo.com
--- grep_error_log eval
qr/matched uri: \/\S+,/
--- grep_error_log_out
matched uri: /*,