diff --git a/apisix/control/router.lua b/apisix/control/router.lua index 86ea7694b7455..3288526b7af77 100644 --- a/apisix/control/router.lua +++ b/apisix/control/router.lua @@ -54,6 +54,9 @@ do local routes = {} local v1_routes = {} local function empty_func() end + local router_opts = { + no_param_match = true + } function fetch_control_api_router() core.table.clear(routes) @@ -83,7 +86,7 @@ function fetch_control_api_router() handler = empty_func, }) - return router.new(routes) + return router.new(routes, router_opts) end end -- do diff --git a/apisix/http/router/radixtree_host_uri.lua b/apisix/http/router/radixtree_host_uri.lua index ad2b31e93192d..bc4d8f8eb3e88 100644 --- a/apisix/http/router/radixtree_host_uri.lua +++ b/apisix/http/router/radixtree_host_uri.lua @@ -86,6 +86,9 @@ end local function empty_func() end +local router_opts = { + no_param_match = true +} local function create_radixtree_router(routes) @@ -115,11 +118,11 @@ local function create_radixtree_router(routes) }) end if #host_router_routes > 0 then - host_router = router.new(host_router_routes) + host_router = router.new(host_router_routes, router_opts) end -- create router: only_uri_router - only_uri_router = router.new(only_uri_routes) + only_uri_router = router.new(only_uri_routes, router_opts) return true end diff --git a/apisix/http/router/radixtree_uri.lua b/apisix/http/router/radixtree_uri.lua index 41ceb6841c615..b034516a5587c 100644 --- a/apisix/http/router/radixtree_uri.lua +++ b/apisix/http/router/radixtree_uri.lua @@ -30,6 +30,9 @@ local _M = {version = 0.2} local uri_routes = {} + local router_opts = { + no_param_match = true + } local uri_router local function create_radixtree_router(routes) routes = routes or {} @@ -81,7 +84,7 @@ local function create_radixtree_router(routes) end core.log.info("route items: ", core.json.delay_encode(uri_routes, true)) - uri_router = router.new(uri_routes) + uri_router = router.new(uri_routes, router_opts) end diff --git a/rockspec/apisix-master-0.rockspec b/rockspec/apisix-master-0.rockspec index bf2912a17c094..a5fc0c8d2d41f 100644 --- a/rockspec/apisix-master-0.rockspec +++ b/rockspec/apisix-master-0.rockspec @@ -42,7 +42,7 @@ dependencies = { "lua-resty-cookie = 0.1.0", "lua-resty-session = 2.24", "opentracing-openresty = 0.1", - "lua-resty-radixtree = 2.5", + "lua-resty-radixtree = 2.6", "lua-protobuf = 0.3.1", "lua-resty-openidc = 1.7.2-1", "luafilesystem = 1.7.0-2", diff --git a/t/router/radixtree-host-uri2.t b/t/router/radixtree-host-uri2.t index eb49091931c0a..3fee146e0adf2 100644 --- a/t/router/radixtree-host-uri2.t +++ b/t/router/radixtree-host-uri2.t @@ -195,3 +195,56 @@ qr/1981/ use config_center: yaml --- no_error_log [error] + + + +=== TEST 6: set route with ':' +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + "uri": "/file:listReputationHistories", + "plugins":{"proxy-rewrite":{"uri":"/hello"}}, + "upstream": { + "nodes": { + "127.0.0.1:1980": 1 + }, + "type": "roundrobin" + } + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error] + + + +=== TEST 7: hit routes +--- request +GET /file:listReputationHistories +--- response_body +hello world +--- no_error_log +[error] + + + +=== TEST 8: not hit +--- request +GET /file:xx +--- error_code: 404 +--- no_error_log +[error] diff --git a/t/router/radixtree-uri-host.t b/t/router/radixtree-uri-host.t index 7dab68c18fe3f..a0d1141225016 100644 --- a/t/router/radixtree-uri-host.t +++ b/t/router/radixtree-uri-host.t @@ -246,3 +246,56 @@ GET /hello?name=json hello world --- no_error_log [error] + + + +=== TEST 15: set route with ':' +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + "uri": "/file:listReputationHistories", + "plugins":{"proxy-rewrite":{"uri":"/hello"}}, + "upstream": { + "nodes": { + "127.0.0.1:1980": 1 + }, + "type": "roundrobin" + } + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error] + + + +=== TEST 16: hit routes +--- request +GET /file:listReputationHistories +--- response_body +hello world +--- no_error_log +[error] + + + +=== TEST 17: not hit +--- request +GET /file:xx +--- error_code: 404 +--- no_error_log +[error]