From b30060c1fd56a9cb4ae7014025e10adffb483c33 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 28 Dec 2023 12:14:20 +0800 Subject: [PATCH] change to fill_atc_context --- kong/router/atc.lua | 10 +++++++--- kong/router/fields.lua | 12 ++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/kong/router/atc.lua b/kong/router/atc.lua index b312d05a63b..c4400d6d154 100644 --- a/kong/router/atc.lua +++ b/kong/router/atc.lua @@ -36,7 +36,7 @@ local check_select_params = utils.check_select_params local get_service_info = utils.get_service_info local route_match_stat = utils.route_match_stat local get_cache_key = fields.get_cache_key -local get_atc_context = fields.get_atc_context +local fill_atc_context = fields.fill_atc_context local DEFAULT_MATCH_LRUCACHE_SIZE = utils.DEFAULT_MATCH_LRUCACHE_SIZE @@ -408,12 +408,14 @@ function _M:matching(params) nil, nil, params.sni, params.headers, params.queries) + self.context:reset() + local host, port = split_host_port(req_host) params.host = host params.port = port - local c, err = get_atc_context(self.context, self.fields, params) + local c, err = fill_atc_context(self.context, self.fields, params) if not c then return nil, err @@ -553,7 +555,9 @@ function _M:matching(params) params.dst_ip, params.dst_port, sni) - local c, err = get_atc_context(self.context, self.fields, params) + self.context:reset() + + local c, err = fill_atc_context(self.context, self.fields, params) if not c then return nil, err end diff --git a/kong/router/fields.lua b/kong/router/fields.lua index 7658a4c5a3b..a33b27c8fcd 100644 --- a/kong/router/fields.lua +++ b/kong/router/fields.lua @@ -287,8 +287,8 @@ local function get_cache_key(fields, params, ctx) end -local function get_atc_context(context, fields, params) - context:reset() +local function fill_atc_context(context, fields, params) + local c = context local res, err = fields_visitor(fields, params, nil, function(field, value) @@ -301,7 +301,7 @@ local function get_atc_context(context, fields, params) -- multiple values for a single query parameter, like /?foo=bar&foo=baz if v_type == "table" then for _, v in ipairs(value) do - local res, err = context:add_value(field, v) + local res, err = c:add_value(field, v) if not res then return nil, err end @@ -319,14 +319,14 @@ local function get_atc_context(context, fields, params) end end - return context:add_value(field, value) + return c:add_value(field, value) end) -- fields_visitor if not res then return nil, err end - return context + return c end @@ -353,7 +353,7 @@ end return { get_cache_key = get_cache_key, - get_atc_context = get_atc_context, + fill_atc_context = fill_atc_context, _set_ngx = _set_ngx, }