From d80edcb5beded39161947b3a3f2d05bcf61d4d82 Mon Sep 17 00:00:00 2001 From: Datong Sun Date: Wed, 15 Jun 2022 04:06:04 -0700 Subject: [PATCH] support `any()` in header matches --- kong/router/atc_compat.lua | 7 ++++--- spec/01-unit/08-router_spec.lua | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/kong/router/atc_compat.lua b/kong/router/atc_compat.lua index 86f4ffde1662..c170bd5d1b4a 100644 --- a/kong/router/atc_compat.lua +++ b/kong/router/atc_compat.lua @@ -243,7 +243,7 @@ local function get_atc(route) for h, v in pairs(route.headers) do local single_header = {} for _, ind in ipairs(v) do - local name = "http.headers." .. h:gsub("-", "_"):lower() + local name = "any(http.headers." .. h:gsub("-", "_"):lower() .. ")" local value = ind local op = "==" if ind:sub(1, 2) == "~*" then @@ -471,8 +471,9 @@ function _M:select(req_method, req_uri, req_host, req_scheme, assert(c:add_value(field, v:lower())) else - -- TODO: support array of values - assert(c:add_value(field, v[1]:lower())) + for _, v in ipairs(v) do + assert(c:add_value(field, v:lower())) + end end end end diff --git a/spec/01-unit/08-router_spec.lua b/spec/01-unit/08-router_spec.lua index 5707e2ff6f71..7fa62043e651 100644 --- a/spec/01-unit/08-router_spec.lua +++ b/spec/01-unit/08-router_spec.lua @@ -1508,7 +1508,7 @@ for _, flavor in ipairs({ "traditional", "traditional_compatible" }) do end) describe("[headers]", function() - it_trad_only("evaluates Routes with more [headers] first", function() + it("evaluates Routes with more [headers] first", function() local use_case = { { service = service,