From f062e208f33e6ab21c6fdc7b5f18038df67c07ee Mon Sep 17 00:00:00 2001 From: joelact Date: Fri, 29 Mar 2024 17:14:07 +0000 Subject: [PATCH] fix(proxy-cache): changes age param The age parameter on the schema was in lower case which caused the header Age to appear only when the kong debug option was enabled. This commit changes the schema parameter from age to Age. Fix #12787 --- changelog/unreleased/kong/fix-age-header.yml | 3 ++ kong-3.8.0-0.rockspec | 1 + kong/clustering/compat/checkers.lua | 18 +++++++++ .../compat/response_headers_translation.lua | 13 ++++++ kong/plugins/proxy-cache/schema.lua | 2 +- .../09-hybrid_mode/09-config-compat_spec.lua | 40 +++++++++++++++++++ .../31-proxy-cache/02-access_spec.lua | 2 +- 7 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/kong/fix-age-header.yml create mode 100644 kong/plugins/proxy-cache/clustering/compat/response_headers_translation.lua diff --git a/changelog/unreleased/kong/fix-age-header.yml b/changelog/unreleased/kong/fix-age-header.yml new file mode 100644 index 00000000000..f3db9eba9be --- /dev/null +++ b/changelog/unreleased/kong/fix-age-header.yml @@ -0,0 +1,3 @@ +message: "proxy-cache response_headers age schema parameter changed from age to Age." +type: bugfix +scope: "Plugin" diff --git a/kong-3.8.0-0.rockspec b/kong-3.8.0-0.rockspec index f0a3a451c2b..bf2167708e3 100644 --- a/kong-3.8.0-0.rockspec +++ b/kong-3.8.0-0.rockspec @@ -538,6 +538,7 @@ build = { ["kong.plugins.proxy-cache.api"] = "kong/plugins/proxy-cache/api.lua", ["kong.plugins.proxy-cache.strategies"] = "kong/plugins/proxy-cache/strategies/init.lua", ["kong.plugins.proxy-cache.strategies.memory"] = "kong/plugins/proxy-cache/strategies/memory.lua", + ["kong.plugins.proxy-cache.clustering.compat.response_headers_translation"] = "kong/plugins/proxy-cache/clustering/compat/response_headers_translation.lua", ["kong.plugins.grpc-web.deco"] = "kong/plugins/grpc-web/deco.lua", ["kong.plugins.grpc-web.handler"] = "kong/plugins/grpc-web/handler.lua", diff --git a/kong/clustering/compat/checkers.lua b/kong/clustering/compat/checkers.lua index 3c9828f56e9..3dd083fd7eb 100644 --- a/kong/clustering/compat/checkers.lua +++ b/kong/clustering/compat/checkers.lua @@ -23,6 +23,24 @@ end local compatible_checkers = { + { 3008000000, --[[ 3.8.0.0 ]] + function (config_table, dp_version, log_suffix) + local has_update + local adapter = require("kong.plugins.proxy-cache.clustering.compat.response_headers_translation").adapter + for _, plugin in ipairs(config_table.plugins or {}) do + if plugin.name == 'proxy-cache' then + has_update = adapter(plugin.config) + if has_update then + log_warn_message('adapts ' .. plugin.name .. ' plugin response_headers configuration to older version', + 'revert to older schema', + dp_version, log_suffix) + end + end + end + + return has_update + end + }, { 3007000000, --[[ 3.7.0.0 ]] function(config_table, dp_version, log_suffix) local has_update diff --git a/kong/plugins/proxy-cache/clustering/compat/response_headers_translation.lua b/kong/plugins/proxy-cache/clustering/compat/response_headers_translation.lua new file mode 100644 index 00000000000..56c602f23bb --- /dev/null +++ b/kong/plugins/proxy-cache/clustering/compat/response_headers_translation.lua @@ -0,0 +1,13 @@ +local function adapter(config_to_update) + if config_to_update.response_headers["Age"] ~= nil then + config_to_update.response_headers.age = config_to_update.response_headers["Age"] + config_to_update.response_headers["Age"] = nil + return true + end + + return false +end + +return { + adapter = adapter +} diff --git a/kong/plugins/proxy-cache/schema.lua b/kong/plugins/proxy-cache/schema.lua index 768e6f06975..34efa9648b5 100644 --- a/kong/plugins/proxy-cache/schema.lua +++ b/kong/plugins/proxy-cache/schema.lua @@ -78,7 +78,7 @@ return { description = "Caching related diagnostic headers that should be included in cached responses", type = "record", fields = { - { age = {type = "boolean", default = true} }, + { ["Age"] = {type = "boolean", default = true} }, { ["X-Cache-Status"] = {type = "boolean", default = true} }, { ["X-Cache-Key"] = {type = "boolean", default = true} }, }, diff --git a/spec/02-integration/09-hybrid_mode/09-config-compat_spec.lua b/spec/02-integration/09-hybrid_mode/09-config-compat_spec.lua index 53d21bf08a0..03867d03041 100644 --- a/spec/02-integration/09-hybrid_mode/09-config-compat_spec.lua +++ b/spec/02-integration/09-hybrid_mode/09-config-compat_spec.lua @@ -472,6 +472,46 @@ describe("CP/DP config compat transformations #" .. strategy, function() admin.plugins:remove({ id = response_rl.id }) end) end) + + describe("proxy-cache plugin", function() + it("rename age field in response_headers config from age to Age", function() + -- [[ 3.8.x ]] -- + local response_rl = admin.plugins:insert { + name = "proxy-cache", + enabled = true, + config = { + response_code = { 200, 301, 404 }, + request_method = { "GET", "HEAD" }, + content_type = { "text/plain", "application/json" }, + cache_ttl = 300, + strategy = "memory", + cache_control = false, + memory = { + dictionary_name = "kong_db_cache", + }, + -- [[ age field renamed to Age + response_headers = { + ["Age"] = true, + ["X-Cache-Status"] = true, + ["X-Cache-Key"] = true + } + -- ]] + } + } + + local expected_response_rl_prior_38 = cycle_aware_deep_copy(response_rl) + expected_response_rl_prior_38.config.response_headers = { + ["age"] = true, + ["X-Cache-Status"] = true, + ["X-Cache-Key"] = true + } + + do_assert(uuid(), "3.7.0", expected_response_rl_prior_38) + + -- cleanup + admin.plugins:remove({ id = response_rl.id }) + end) + end) end) describe("ai plugins", function() diff --git a/spec/03-plugins/31-proxy-cache/02-access_spec.lua b/spec/03-plugins/31-proxy-cache/02-access_spec.lua index 1dc0c5bb930..665e23fade0 100644 --- a/spec/03-plugins/31-proxy-cache/02-access_spec.lua +++ b/spec/03-plugins/31-proxy-cache/02-access_spec.lua @@ -329,7 +329,7 @@ do content_type = { "text/plain", "application/json" }, [policy] = policy_config, response_headers = { - age = false, + ["Age"] = false, ["X-Cache-Status"] = false, ["X-Cache-Key"] = false },