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: error occurs if the opt.vars is not passed #146

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion lib/resty/radixtree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ local function match_route_opts(route, opts, args)
local len = #hosts
for i = 1, len, 2 do
if str_find(hosts[i+1], ":", 1, true) then
if opts.vars.http_host then
if opts.vars and opts.vars.http_host then
host = opts.vars.http_host
end
else
Expand Down
27 changes: 27 additions & 0 deletions t/add.t
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,30 @@ GET /t
--- response_body
pass
true



=== TEST 7: match failed if http_host is not passed
--- config
location /t {
content_by_lua_block {
local opts = {host = "127.0.0.1"}
local radix = require("resty.radixtree")
local rx = radix.new({
{
paths = {"/aa*"},
hosts = "127.0.0.1:9080",
xuruidong marked this conversation as resolved.
Show resolved Hide resolved
handler = function (ctx)
ngx.say("pass")
end
}
})
ngx.say(rx:dispatch("/aa", opts))
}
}
--- request
GET /t
--- no_error_log
[error]
--- response_body
nil
Loading