Skip to content

Commit

Permalink
fix(proxy-cache): changes age param
Browse files Browse the repository at this point in the history
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
  • Loading branch information
joelact committed May 27, 2024
1 parent aae1815 commit f062e20
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/kong/fix-age-header.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "proxy-cache response_headers age schema parameter changed from age to Age."
type: bugfix
scope: "Plugin"
1 change: 1 addition & 0 deletions kong-3.8.0-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 18 additions & 0 deletions kong/clustering/compat/checkers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion kong/plugins/proxy-cache/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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} },
},
Expand Down
40 changes: 40 additions & 0 deletions spec/02-integration/09-hybrid_mode/09-config-compat_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion spec/03-plugins/31-proxy-cache/02-access_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down

0 comments on commit f062e20

Please sign in to comment.