Cookies - set on non-cached pages, read on all pages

David Murphy David at firechaser.com
Tue Apr 20 17:08:18 CEST 2010


Thanks Rich

When you say ignore  do you mean unset e.g.

sub vcl_recv {
   //snip
  unset req.http.cookie;
}


sub vcl_fetch {
    //beresp replaces obj in 2.1
    unset beresp.http.set-cookie;
}

We've tried several combinations of unsetting cookies so that the cached pages are not duplicated for each client, but without much luck. What we find is that a cookie set in the browser on the /login page is not available on subsequent cached Varnish pages. 

That said, I'm glad you've got something similar working. So when you view your Varnish stats you see just a single instance of a cached page e.g. /about-us or whatever, and when that page is viewed by different users with different cookie values, the expected "Hello <some_name>" appears just fine?

Best, David

________________________________________
From: Richard Chiswell [richard.chiswell at mangahigh.com]
Sent: 20 April 2010 15:41
To: David Murphy
Cc: varnish-misc at varnish-cache.org
Subject: Re: Cookies - set on non-cached pages, read on all pages

Hi David,

> We use a javascript cookie to display the user's first name in the header of our site. Our site uses Varnish to cache all pages except a login page, where the cookie is set.
>
> What we need to be able to do is set the cookie once (name='David') on the login page so that we can display 'Hello David' on all other pages.
>
> For a given cached page, if the user's browser already has a cookie saved, then we display its value ('Hello David'). If no cookie is found then we display 'Login'.
We've done something similar - just get Varnish to ignore the cookie
entirely and then just use Javascript to check for the cookie and write
out the data. If there is no cookie, it shows "Login".

Rich




More information about the varnish-misc mailing list