Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Integralist/835e6ce181584bec9ba6391d29ebaf12 to your computer and use it in GitHub Desktop.
Save Integralist/835e6ce181584bec9ba6391d29ebaf12 to your computer and use it in GitHub Desktop.
[Varnish VCL] use vcl to store provided query string and path into HTTP response headers #tags: vcl, varnish
vcl 4.0;
backend default {
.host = "www.vclfiddle.net";
.port = "80";
}
sub vcl_recv {
if (req.url ~ "(foo/bar)") {
set req.http.X-QS = regsub(req.url, "^[^?]+\?", ""); // good=hey&bad1=true&bad2=boop
set req.http.X-Path = regsub(req.url, "\?.+$", ""); // /foo/bar
}
}
/*
curl http://www.vclfiddle.net/foo/bar?good=hey&bad1=true&bad2=boop --header 'User-Agent: vclFiddle'
http://vclfiddle.net/161102-3c995c5/44
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment