Varnish and language cookie

Cosimo Streppone cosimo at streppone.it
Fri Feb 19 00:08:45 CET 2010


In data 18 febbraio 2010 alle ore 21:58:39, Alessandro Ronchi  
<alessandro.ronchi at soasi.com> ha scritto:

> This is my configuration file:
> http://dpaste.com/161264/

Ciao Alessandro,

I'm no expert, but I think your config file
explicitly defeats caching when there is a cookie.

41  if (req.http.Authorization || req.http.Cookie) {

> I've used
> set req.hash += req.http.cookie;

I would suggest explicitly matching the "django_language"
cookie, setting a custom header with its contents, and
then using that as a hash part, so:

In vcl_recv():

     set req.http.X-Cookie-Language = regsub(req.http.Cookie, "...");

In vcl_hash():

     set req.hash += req.http.X-Cookie-Language;

This is part of one config I'm using, the vcl_recv() bit:

     if (req.http.Cookie ~ "language=") {
         set req.http.X-Varnish-Language =
             regsub(req.http.Cookie, "^.*?language=([^;]*?);*.*$", "\1");
     }

The regexp above is probably overly complicated.
I tried a couple of times to simplify it, but I always broke it.
Suggestions welcome :)

-- 
Cosimo



More information about the varnish-misc mailing list