Last active
October 1, 2018 14:07
-
-
Save KINKCreative/10224621 to your computer and use it in GitHub Desktop.
Varnish - remove Vary: User-Agent header
This file contains 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
// ADD TO YOUR VCL FILE | |
sub vcl_fetch { | |
if (beresp.http.Vary ~ "User-Agent") { | |
set beresp.http.Vary = regsub(req.http.Vary, ",? *User-Agent *", ""); | |
set beresp.http.Vary = regsub(req.http.Vary, "^, *", ""); | |
if (beresp.http.Vary == "") { | |
remove beresp.http.Vary; | |
} | |
} | |
if (beresp.ttl <= 0s || | |
beresp.http.Set-Cookie || | |
beresp.http.Vary == "*") { | |
/* | |
* Mark as "Hit-For-Pass" for the next 2 minutes | |
*/ | |
set beresp.ttl = 120 s; | |
return (hit_for_pass); | |
} | |
return (deliver); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thies doesn't work in newer varnish versions because req.http is no longer available in vcl_backend_response