From fa56132e49d41595ba1681467adb828694cf0086 Mon Sep 17 00:00:00 2001 From: Dan Carley Date: Thu, 7 Aug 2014 15:19:34 +0100 Subject: [PATCH] Don't cache CC no-store/no-cache Don't cache responses with these headers. In order to match: - CloudFlare's default behaviour - cdn-acceptance-tests mocks: https://github.com/alphagov/cdn-acceptance-tests/commit/47585a28adab2147bda0a099984ed9163e6aa690 - cache-N.router config: https://github.gds/gds/puppet/commit/8c5c1876b3860fad386357bfdc0b94d12c03c878 This should come next to the handling of CC private because we want to do this after 5xx handling and return() before doing anything. I've opened and closed the comments to indicate that this isn't part of the macro that we've copied. Run against the acceptance test service. Two errors are pre-existing: dcarley@ci-slave-4:~/cdn-acceptance-tests$ go test -edgeHost fastly.cdn-acceptance-test.alphagov.co.uk -skipVerifyTLS -skipFailover 2014/08/07 14:17:26 Confirming that CDN is healthy 2014/08/07 14:17:26 Started server on port 8080 2014/08/07 14:17:26 Checking health of origin... 2014/08/07 14:17:27 origin is up! --- FAIL: TestNoCacheHeaderCookie (0.08 seconds) helpers.go:360: Incorrect response body. Expected "second response", got "first response" helpers.go:360: Incorrect response body. Expected "third response", got "first response" --- FAIL: TestNoCacheHeaderCacheControlMaxAge0 (0.02 seconds) helpers.go:360: Incorrect response body. Expected "second response", got "first response" helpers.go:360: Incorrect response body. Expected "third response", got "first response" 2014/08/07 14:17:54 Started server on port 33265 2014/08/07 14:17:54 Started server on port 33265 2014/08/07 14:17:54 Started server on port 49001 2014/08/07 14:17:55 Started server on port 46997 2014/08/07 14:17:55 Started server on port 39178 FAIL exit status 1 FAIL _/home/dcarley/cdn-acceptance-tests 28.134s --- vcl_templates/www.vcl.erb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vcl_templates/www.vcl.erb b/vcl_templates/www.vcl.erb index 7d9f4478..371de8bc 100644 --- a/vcl_templates/www.vcl.erb +++ b/vcl_templates/www.vcl.erb @@ -185,6 +185,14 @@ sub vcl_fetch { return (pass); } + # << not reproduced by macro + # >> custom + if (beresp.http.Cache-Control ~ "no-(store|cache)") { + return (pass); + } + # << custom + # >> not reproduced by macro + if (beresp.status >= 500 && beresp.status <= 599) { set req.http.Fastly-Cachetype = "ERROR"; set beresp.ttl = 1s;