Skip to content

Commit

Permalink
fix: error occurs if the opt.vars is not passed (#146)
Browse files Browse the repository at this point in the history
Signed-off-by: xuruidong <xuruidong@gmail.com>
  • Loading branch information
xuruidong authored Aug 16, 2024
1 parent 2e8f493 commit 262d798
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
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"},
handler = function (ctx)
ngx.say("pass")
end
}
})
ngx.say(rx:dispatch("/aa", opts))
}
}
--- request
GET /t
--- no_error_log
[error]
--- response_body
nil

0 comments on commit 262d798

Please sign in to comment.