Skip to content

Commit

Permalink
change to fill_atc_context
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw authored and dndx committed Dec 28, 2023
1 parent 04a4241 commit b30060c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
10 changes: 7 additions & 3 deletions kong/router/atc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions kong/router/fields.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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


Expand All @@ -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,
}

0 comments on commit b30060c

Please sign in to comment.