You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2021/09/21 12:13:15 UTC
[apisix] branch master updated: fix(radixtree_host_uri): correct
matched path (#5104)
This is an automated email from the ASF dual-hosted git repository.
spacewander 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 034d231 fix(radixtree_host_uri): correct matched path (#5104)
034d231 is described below
commit 034d231183365987b7807e594751fffe8fc4a8f7
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Tue Sep 21 20:13:10 2021 +0800
fix(radixtree_host_uri): correct matched path (#5104)
Fix #5077
Signed-off-by: spacewander <sp...@gmail.com>
---
apisix/http/router/radixtree_host_uri.lua | 5 ++
t/router/radixtree-host-uri3.t | 108 ++++++++++++++++++++++++++++++
2 files changed, 113 insertions(+)
diff --git a/apisix/http/router/radixtree_host_uri.lua b/apisix/http/router/radixtree_host_uri.lua
index 250dc27..8ae7a99 100644
--- a/apisix/http/router/radixtree_host_uri.lua
+++ b/apisix/http/router/radixtree_host_uri.lua
@@ -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
}
@@ -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
diff --git a/t/router/radixtree-host-uri3.t b/t/router/radixtree-host-uri3.t
index 42c6faf..1cb3ee6 100644
--- a/t/router/radixtree-host-uri3.t
+++ b/t/router/radixtree-host-uri3.t
@@ -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: /*,