Skip to content

Instantly share code, notes, and snippets.

@KINKCreative
Last active October 1, 2018 14:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KINKCreative/10224621 to your computer and use it in GitHub Desktop.
Save KINKCreative/10224621 to your computer and use it in GitHub Desktop.
Varnish - remove Vary: User-Agent header
// 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);
}
@DaspawnW
Copy link

DaspawnW commented Oct 1, 2018

Thies doesn't work in newer varnish versions because req.http is no longer available in vcl_backend_response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment