Skip to content

Commit

Permalink
fix(proxy-cache): set Header Accept-Encoding as default values of v…
Browse files Browse the repository at this point in the history
…ary_headers

Currently, proxy-cache might mix the compression and uncompression
values while cacheing, and return runexpected compression response to
the request if users didn't specify the vary_headers.
  • Loading branch information
git-hulk committed Apr 16, 2024
1 parent 1714e26 commit 07dcb59
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions kong/plugins/proxy-cache/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ return {
elements = { type = "string" },
}},
{ vary_headers = { description = "Relevant headers considered for the cache key. If undefined, none of the headers are taken into consideration.", type = "array",
default = { "Accept-Encoding" },
elements = { type = "string" },
}},
{ response_headers = {
Expand Down
7 changes: 7 additions & 0 deletions spec/03-plugins/31-proxy-cache/01-schema_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ describe("proxy-cache schema", function()
assert.is_truthy(entity)
end)

it("defines default vary_headers values", function()
local config = { strategy = "memory" }
local entity, err = v(config, proxy_cache_schema)
assert.is_nil(err)
assert.is_truthy(entity)
assert.same(entity.config.vary_headers, { "Accept-Encoding" })
end)
it("supports vary_headers values", function()
local entity, err = v({
strategy = "memory",
Expand Down
11 changes: 11 additions & 0 deletions spec/03-plugins/31-proxy-cache/03-api_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,17 @@ describe("Plugin: proxy-cache", function()
assert.res_status(200, res)
assert.same("Miss", res.headers["X-Cache-Status"])
end)
it("miss if pass the Accept-Encoding", function()
local res = assert(proxy_client:get("/get", {
headers = {
host = "route-1.test",
["kong-debug"] = 1,
["Accept-Encoding"] = "gzip",
}
}))
assert.res_status(200, res)
assert.same("Miss", res.headers["X-Cache-Status"])
end)
it("purge all the cache entries", function()
-- make a `Hit` request to `route-1`
local res = assert(proxy_client:get("/get", {
Expand Down

0 comments on commit 07dcb59

Please sign in to comment.