Last active
February 15, 2018 21:43
-
-
Save wheaties/58c9f860e06640eb53e7a6b3a87f2750 to your computer and use it in GitHub Desktop.
Cache both HEAD and GET requests separately in Fastly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub vcl_hash { | |
set req.hash += req.url; | |
set req.hash += req.http.host; | |
if (req.http.request-method) { | |
set req.hash += req.http.request-method; | |
} | |
return (lookup); | |
} | |
sub vcl_miss { | |
#don't turn HEAD requests into GET requests | |
if(req.http.request-method){ | |
set bereq.request = bereq.http.request-method; | |
unset req.http.request-method; | |
} | |
#FASTLY miss | |
return(fetch); | |
} | |
sub vcl_pass { | |
if(req.http.request-method){ | |
set bereq.request = bereq.http.request-method; | |
unset req.http.request-method; | |
} | |
#FASTLY pass | |
} | |
sub vcl_recv { | |
if(req.request == "HEAD"){ | |
set req.http.request-method = req.request; | |
} | |
#and lot's more fun stuff... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment