Re:Researching a new form of HTTP caching optimization
by cheald on Tuesday January 06, 2015 @01:26PM
(#8846070)
Off the top of my head:
sub vcl_recv {
set req.http.X-Custom-Cookie-Value = regsub(req.http.cookie, ".*;|^)YOUR_COOKIE_NAME=([^;]+)(;.*|$)", "\2");
}
Then you can just: sub vcl_hash {
set req.hash += req.http.X-Custom-Cookie-Value;
}
And now you're cache segmented on that cookie value.
Re:Researching a new form of HTTP caching optimization
by Argorak on Tuesday January 06, 2015 @09:45AM
(#8844515)
You will probably have to write a VCL plugin if you want to parse the cookie, but that's not a huge hassle.
Re:Researching a new form of HTTP caching optimization
by acdha on Tuesday January 06, 2015 @11:33AM
(#8845182)
You can handle cookies in pure VCL – the code's not particularly elegant but it's manageable for light usage:
https://www.varnish-cache.org/trac/wiki/VCLExampleRemovingSo...
Re:Researching a new form of HTTP caching optimization
by Argorak on Tuesday January 06, 2015 @01:12PM
(#8845967)
I'm not sure whether I would call "munging the cookie header with regexps" "cookie handling" ;).
Re:Researching a new form of HTTP caching optimization
by acdha on Tuesday January 06, 2015 @01:16PM
(#8846002)
Agreed – it's possible and for simple tasks such as stripping an analytics cookie it's workable but for anything more serious you'd want something like https://github.com/lkarsten/libvmod-cookie
I couldn't (quickly) find documentation on how to get the value of a specific cookie, but the server could send a user ID in a header or something Varnish can easily access to be used in the above function.