From 03cb1fc5794658b89ed9f80ab5ca3c0b98a7afe7 Mon Sep 17 00:00:00 2001 From: Dan Carley Date: Thu, 26 Sep 2013 10:31:45 +0100 Subject: [PATCH] Add some stuff not reproduced by macros https://gist.github.com/dcarley/e31b5b9fabbde6d7c9cb https://fastly.zendesk.com/requests/2176 --- govuk.vcl | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/govuk.vcl b/govuk.vcl index e872da99..642f29a9 100644 --- a/govuk.vcl +++ b/govuk.vcl @@ -54,10 +54,52 @@ sub vcl_recv { # << custom recv #FASTLY recv + + # >> not reproduced by macro + if (req.request != "HEAD" && req.request != "GET" && req.request != "PURGE") { + return(pass); + } + + return(lookup); + # << not reproduced by macro } sub vcl_fetch { #FASTLY fetch + + # >> not reproduced by macro + if ((beresp.status == 500 || beresp.status == 503) && req.restarts < 1 && (req.request == "GET" || req.request == "HEAD")) { + restart; + } + + if(req.restarts > 0 ) { + set beresp.http.Fastly-Restarts = req.restarts; + } + + if (beresp.http.Set-Cookie) { + set req.http.Fastly-Cachetype = "SETCOOKIE"; + return (pass); + } + + if (beresp.http.Cache-Control ~ "private") { + set req.http.Fastly-Cachetype = "PRIVATE"; + return (pass); + } + + if (beresp.status == 500 || beresp.status == 503) { + set req.http.Fastly-Cachetype = "ERROR"; + set beresp.ttl = 1s; + set beresp.grace = 5s; + return (deliver); + } + + if (beresp.http.Expires || beresp.http.Surrogate-Control ~ "max-age" || beresp.http.Cache-Control ~"(s-maxage|max-age)") { + # keep the ttl here + } else { + # apply the default ttl + set beresp.ttl = 3600s; + } + # << not reproduced by macro } sub vcl_hit { @@ -85,5 +127,11 @@ sub vcl_pass { } sub vcl_hash { -#FASTLY hash + # >> not reproduced by macro + # `FASTLY hash` only appends `#####GENERATION#####` + set req.hash += req.url; + set req.hash += req.http.host; + set req.hash += "#####GENERATION#####"; + return (hash); + # << not reproduced by macro }