Skip to content

Instantly share code, notes, and snippets.

@wheaties
Last active February 15, 2018 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wheaties/58c9f860e06640eb53e7a6b3a87f2750 to your computer and use it in GitHub Desktop.
Save wheaties/58c9f860e06640eb53e7a6b3a87f2750 to your computer and use it in GitHub Desktop.
Cache both HEAD and GET requests separately in Fastly
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