diff --git a/kong/plugins/proxy-cache/schema.lua b/kong/plugins/proxy-cache/schema.lua index 768e6f06975f..154c97a593e2 100644 --- a/kong/plugins/proxy-cache/schema.lua +++ b/kong/plugins/proxy-cache/schema.lua @@ -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 = { diff --git a/spec/03-plugins/31-proxy-cache/01-schema_spec.lua b/spec/03-plugins/31-proxy-cache/01-schema_spec.lua index 9d2bab2d46a1..3cf833f8ef92 100644 --- a/spec/03-plugins/31-proxy-cache/01-schema_spec.lua +++ b/spec/03-plugins/31-proxy-cache/01-schema_spec.lua @@ -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", diff --git a/spec/03-plugins/31-proxy-cache/03-api_spec.lua b/spec/03-plugins/31-proxy-cache/03-api_spec.lua index ac5268396fb9..1a994ddc8108 100644 --- a/spec/03-plugins/31-proxy-cache/03-api_spec.lua +++ b/spec/03-plugins/31-proxy-cache/03-api_spec.lua @@ -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", {