-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: cached hit "path" when enabled prefix matching and
matched
…
- Loading branch information
1 parent
6b5d65e
commit b725eeb
Showing
2 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
# vim:set ft= ts=4 sw=4 et fdm=marker: | ||
|
||
use t::RX 'no_plan'; | ||
|
||
repeat_each(1); | ||
run_tests(); | ||
|
||
__DATA__ | ||
|
||
=== TEST 1: prefix matching with method, and matched is not nil. | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local radix = require("resty.radixtree") | ||
local rx = radix.new({ | ||
{ | ||
paths = "/hello*", | ||
methods = {"GET"}, | ||
metadata = "metadata prefix matching with GET, matched = {}", | ||
}, | ||
}) | ||
local opts = {method = "GET", matched = {}} | ||
ngx.say(rx:match("/hello1", opts)) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- no_error_log | ||
[error] | ||
--- response_body | ||
metadata prefix matching with GET, matched = {} | ||
|
||
|
||
|
||
=== TEST 2: prefix matching with host, and matched is not nil. | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local json = require("cjson.safe") | ||
local radix = require("resty.radixtree") | ||
local rx = radix.new({ | ||
{ | ||
paths = "/hello*", | ||
hosts = {"foo.com"}, | ||
metadata = "metadata prefix matching with host, matched = {}", | ||
}, | ||
}) | ||
local opts = {host = "foo.com", matched = {}} | ||
ngx.say(rx:match("/hello1", opts)) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- no_error_log | ||
[error] | ||
--- response_body | ||
metadata prefix matching with host, matched = {} | ||
|
||
|
||
|
||
=== TEST 3: prefix matching with vars, and matched is not nil. | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local json = require("cjson.safe") | ||
local radix = require("resty.radixtree") | ||
local rx = radix.new({ | ||
{ | ||
paths = "/hello*", | ||
vars = { | ||
{"arg_k", "==", "v"}, | ||
}, | ||
metadata = "metadata prefix matching with host, matched = {}", | ||
}, | ||
}) | ||
local opts = {vars = ngx.var, matched = {}} | ||
ngx.say(rx:match("/hello1", opts)) | ||
} | ||
} | ||
--- request | ||
GET /t?k=v | ||
--- no_error_log | ||
[error] | ||
--- response_body | ||
metadata prefix matching with host, matched = {} | ||
|
||
|
||
|
||
=== TEST 4: prefix matching with method, host, vars and matched is not nil. | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local json = require("cjson.safe") | ||
local radix = require("resty.radixtree") | ||
local rx = radix.new({ | ||
{ | ||
paths = "/hello*", | ||
hosts = {"foo.com"}, | ||
methods = {"GET"}, | ||
vars = { | ||
{"arg_k", "==", "v"}, | ||
}, | ||
metadata = "metadata prefix matching with method, host, vars, matched = {}", | ||
}, | ||
}) | ||
local opts = { | ||
method = "GET", | ||
host = "foo.com", | ||
vars = ngx.var, | ||
matched = {} | ||
} | ||
ngx.say(rx:match("/hello1", opts)) | ||
} | ||
} | ||
--- request | ||
GET /t?k=v | ||
--- no_error_log | ||
[error] | ||
--- response_body | ||
metadata prefix matching with method, host, vars, matched = {} | ||
|
||
|
||
|
||
=== TEST 5: get matched when callback route.handler after dispatch success | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local json = require("cjson.safe") | ||
local radix = require("resty.radixtree") | ||
local rx = radix.new({ | ||
{ | ||
paths = "/hello*", | ||
hosts = {"foo.com"}, | ||
methods = {"GET"}, | ||
vars = { | ||
{"arg_k", "==", "v"}, | ||
}, | ||
handler = function (opts) | ||
ngx.say("after dispatch success get matched: ", json.encode(opts.matched)) | ||
end, | ||
}, | ||
}) | ||
local opts = { | ||
method = "GET", | ||
host = "foo.com", | ||
vars = ngx.var, | ||
matched = {} | ||
} | ||
rx:dispatch("/hello1", opts, opts) | ||
} | ||
} | ||
--- request | ||
GET /t?k=v | ||
--- no_error_log | ||
[error] | ||
--- response_body | ||
after dispatch success get matched: {"_path":"\/hello*","_method":"GET","_host":"foo.com"} |