From 52bd602487f3176a93945cf758dc1df319500c57 Mon Sep 17 00:00:00 2001 From: theweakgod <1031205858@qq.com> Date: Thu, 30 Nov 2023 18:29:12 +0800 Subject: [PATCH] fix --- lib/resty/radixtree.lua | 2 ++ t/add.t | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/resty/radixtree.lua b/lib/resty/radixtree.lua index 80a2596..aefb89e 100644 --- a/lib/resty/radixtree.lua +++ b/lib/resty/radixtree.lua @@ -743,6 +743,8 @@ local function match_route_opts(route, opts, args) if opts.vars.http_host then host = opts.vars.http_host end + else + host = opts.host end if match_host(hosts[i], hosts[i + 1], host) then if opts_matched_exists then diff --git a/t/add.t b/t/add.t index 6e3b6b8..4046781 100644 --- a/t/add.t +++ b/t/add.t @@ -193,3 +193,31 @@ GET /t --- response_body pass true + + + +=== TEST 6: match many host +--- config + location /t { + content_by_lua_block { + local opts = {vars = {http_host = "127.0.0.1:9980"}, host = "127.0.0.1"} + local radix = require("resty.radixtree") + local rx = radix.new({ + { + paths = {"/aa*"}, + hosts = {"www.foo.com:9080", "127.0.0.1:9991", "www.bar.com:9200", "127.0.0.1"}, + handler = function (ctx) + ngx.say("pass") + end + } + }) + ngx.say(rx:dispatch("/aa", opts)) + } + } +--- request +GET /t +--- no_error_log +[error] +--- response_body +pass +true