From b4346ced983ed8ae94dc0305230914aa89ad7cc4 Mon Sep 17 00:00:00 2001 From: Chrono Date: Thu, 9 Nov 2023 12:01:39 +0800 Subject: [PATCH] refactor(router): simplify the functions of cache calculation (#11948) --- kong/router/atc.lua | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/kong/router/atc.lua b/kong/router/atc.lua index 8affb6e7ac9..a0e2ebd2c73 100644 --- a/kong/router/atc.lua +++ b/kong/router/atc.lua @@ -596,12 +596,14 @@ do local str_buf = buffer.new(64) - get_headers_key = function(headers) + local function get_headers_or_queries_key(values, lower_func) str_buf:reset() -- NOTE: DO NOT yield until str_buf:get() - for name, value in pairs(headers) do - local name = replace_dashes_lower(name) + for name, value in pairs(values) do + if lower_func then + name = lower_func(name) + end if type(value) == "table" then tb_sort(value) @@ -614,20 +616,12 @@ do return str_buf:get() end - get_queries_key = function(queries) - str_buf:reset() - - -- NOTE: DO NOT yield until str_buf:get() - for name, value in pairs(queries) do - if type(value) == "table" then - tb_sort(value) - value = tb_concat(value, ", ") - end - - str_buf:putf("|%s=%s", name, value) - end + get_headers_key = function(headers) + return get_headers_or_queries_key(headers, replace_dashes_lower) + end - return str_buf:get() + get_queries_key = function(queries) + return get_headers_or_queries_key(queries) end end