Skip to content

Commit 262d798

Browse files
authored
fix: error occurs if the opt.vars is not passed (#146)
Signed-off-by: xuruidong <[email protected]>
1 parent 2e8f493 commit 262d798

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/resty/radixtree.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ local function match_route_opts(route, opts, args)
749749
local len = #hosts
750750
for i = 1, len, 2 do
751751
if str_find(hosts[i+1], ":", 1, true) then
752-
if opts.vars.http_host then
752+
if opts.vars and opts.vars.http_host then
753753
host = opts.vars.http_host
754754
end
755755
else

t/add.t

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,30 @@ GET /t
221221
--- response_body
222222
pass
223223
true
224+
225+
226+
227+
=== TEST 7: match failed if http_host is not passed
228+
--- config
229+
location /t {
230+
content_by_lua_block {
231+
local opts = {host = "127.0.0.1"}
232+
local radix = require("resty.radixtree")
233+
local rx = radix.new({
234+
{
235+
paths = {"/aa*"},
236+
hosts = {"127.0.0.1:9080"},
237+
handler = function (ctx)
238+
ngx.say("pass")
239+
end
240+
}
241+
})
242+
ngx.say(rx:dispatch("/aa", opts))
243+
}
244+
}
245+
--- request
246+
GET /t
247+
--- no_error_log
248+
[error]
249+
--- response_body
250+
nil

0 commit comments

Comments
 (0)