diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a24ec24c..0aeb45229 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed issues on OIDC jwk discovery [PR #1268](https://github.com/3scale/APIcast/pull/1268) [THREESCALE-6913](https://issues.redhat.com/browse/THREESCALE-6913) - Fixed Payload limit content-length response header [PR #1266](https://github.com/3scale/APIcast/pull/1266) [THREESCALE-6736](https://issues.redhat.com/browse/THREESCALE-6736) - Fixed IPcheck policy issues with invalid IP [PR #1273](https://github.com/3scale/APIcast/pull/1273) [THREESCALE-7075](https://issues.redhat.com/browse/THREESCALE-7075) - +- Disabled content-caching globally if no policy at all [PR #1278](https://github.com/3scale/APIcast/pull/1278) [THREESCALE-7016](https://issues.redhat.com/browse/THREESCALE-7016) ### Added @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). + ## [3.10.0] 2021-01-04 Beta1 is stable and moved to final release. diff --git a/gateway/conf.d/apicast.conf b/gateway/conf.d/apicast.conf index 6a906b7d2..7c8346a2e 100644 --- a/gateway/conf.d/apicast.conf +++ b/gateway/conf.d/apicast.conf @@ -77,7 +77,7 @@ location @upstream { } #{% capture proxy_cache_valid %} - #{#} proxy_cache apicast_cache; + #{#} proxy_cache $cache_zone; #{#} proxy_cache_key $scheme$request_method$proxy_host$request_uri$service_id; #{#} proxy_no_cache $cache_request; #{#} proxy_cache_valid {{ env.APICAST_CACHE_STATUS_CODES | default: '200 302'}} {{ env.APICAST_CACHE_MAX_TIME | default: '1m' }}; @@ -166,6 +166,7 @@ location / { # Variable to enable/disable content cache set $cache_request 'true'; + set $cache_zone 'off'; set $original_request_id $request_id; set $upstream_keepalive_key ""; diff --git a/gateway/src/apicast/policy/content_caching/content_caching.lua b/gateway/src/apicast/policy/content_caching/content_caching.lua index da751f16f..058137c03 100644 --- a/gateway/src/apicast/policy/content_caching/content_caching.lua +++ b/gateway/src/apicast/policy/content_caching/content_caching.lua @@ -11,6 +11,8 @@ local metrics_updater = require('apicast.metrics.updater') local content_cache_metric = prometheus('counter', "content_caching", "Content caching status", {"status"}) +local cache_zone = "apicast_cache" + local new = _M.new function _M.new(config) @@ -30,7 +32,9 @@ function _M.new(config) end function _M:access(context) + ngx.var.cache_zone = cache_zone ngx.var.cache_request = "true" + for _, rule in ipairs(self.rules or {}) do local cond_is_true = rule.condition:evaluate(context) if cond_is_true and rule.cache then diff --git a/t/apicast-policy-content-caching.t b/t/apicast-policy-content-caching.t index 690be7396..4eb457702 100644 --- a/t/apicast-policy-content-caching.t +++ b/t/apicast-policy-content-caching.t @@ -429,3 +429,107 @@ __DATA__ ["X-Cache-Status: MISS", "X-Cache-Status: MISS"] --- no_error_log [error] + + + +=== TEST 8: HEAD request is enabled if no content-caching +This is related to https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_convert_head +and THREESCALE-7016 +--- configuration +{ + "services": [ + { + "id": 42, + "proxy": { + "hosts": ["one"], + "policy_chain": [ + { + "name": "apicast.policy.upstream", + "configuration": + { + "rules": [ { "regex": "/", "url": "http://test:$TEST_NGINX_SERVER_PORT/" } ] + } + } + ] + } + } + ] +} +--- upstream + location / { + content_by_lua_block { + local assert = require('luassert') + assert.same(ngx.var.request_method, "HEAD") + } + } +--- request +HEAD /foo +--- more_headers +Host: one +--- expected_response_body_like_multiple eval +yay, api backend +--- error_code: 200 +--- no_error_log +[error] + +=== TEST 9: HEAD request is disabled when using content-caching +This is related to https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_convert_head +and THREESCALE-7016 +--- configuration +{ + "services": [ + { + "id": 42, + "proxy": { + "hosts": ["one"], + "policy_chain": [ + { + "name": "apicast.policy.content_caching", + "version": "builtin", + "configuration": { + "rules": [ + { + "cache": true, + "header": "X-Cache-Status", + "condition": { + "combine_op": "and", + "operations": [ + { + "left": "oo", + "op": "==", + "right": "oo" + } + ] + } + } + ] + } + }, + { + "name": "apicast.policy.upstream", + "configuration": + { + "rules": [ { "regex": "/", "url": "http://test:$TEST_NGINX_SERVER_PORT/" } ] + } + } + ] + } + } + ] +} +--- upstream + location / { + content_by_lua_block { + local assert = require('luassert') + assert.same(ngx.var.request_method, "GET") + } + } +--- request +HEAD /foo +--- more_headers +Host: one +--- expected_response_body_like_multiple eval +yay, api backend +--- error_code: 200 +--- no_error_log +[error]