plone.recipe.varnish does not cache any requests with cookies

Bug #276894 reported by Laurence Rowe
6
Affects Status Importance Assigned to Milestone
collective.buildout
New
Undecided
Unassigned

Bug Description

I'm using varnish 2.0-beta2 with plone.recipe.varnish 1.0rc6. I have mod_proxy_balancer setup to use sticky sessions cookie generate by mod_headers with:

Header add Set-Cookie "__balancer_zopes=route.%{BALANCER_WORKER_ROUTE}e; path=/;" env=BALANCER_ROUTE_CHANGED

The result is that no pages get cached at all, as there is always a Cookie header in the request. Presumably this observation would also hold true for all logged in users too with the __ac cookie even without the stickysession cookies, or users with the google analytics __utm. cookies.

To fix this I had to customise the vcl. Ideally I would have liked to ignore only double underscore cookies, but I couldn't quite work out how.

I think this would be safe for the default CacheSetup configuration, though it may cause problems if you want to cache html pages. Maybe for that case there should be some more logic in a sub vcl_hit to force a pass if the content type is text/html and the user is authenticated.

Index: varnish.vcl
===================================================================
--- varnish.vcl (revision 690)
+++ varnish.vcl (working copy)
@@ -30,6 +30,14 @@
  if (req.http.If-None-Match) {
   pass;
  }
+
+ # ignore cookies starting with underscore
+ if (req.request == "GET" && !(req.http.Authorization) && req.http.cookie) {
+ if (req.http.cookie ~ "(^| )[^_](.+?)($|;)") {
+ pass;
+ }
+ lookup;
+ }
 }

 sub vcl_pipe {

Revision history for this message
Laurence Rowe (lrowe) wrote :

Following up from discussions elsewhere:

I'm agnostic as to the open-ending of the generated vcl-config. It's ike a nice idea and seems to be the recommended approach from reading the varnish docs, but it does seem to hide some complexity.

Regardless, I think we need to solve this issue of caching requests with cookies, the current behaviour is largely useless for a Plone site.

Revision history for this message
newbery (ric-digitalmarbles) wrote : Re: [Bug 276894] Re: plone.recipe.varnish does not cache any requests with cookies

I assume you are referring to this discussion...
https://sourceforge.net/mailarchive/message.php?msg_name=8167CFDC-B2B3-4098-A406-6941E21462C7%40digitalmarbles.com

Note, as far as I know, neither the varnish docs nor the varnish
developers have ever "recommended" open-ending a customized vcl config.

Also... as mentioned in the referenced discussion, I'm not sure yet
whether this launchpad bug tracker is the correct designated channel
for this discussion.

Ric

On Oct 21, 2008, at 10:29 AM, Laurence Rowe wrote:

> Following up from discussions elsewhere:
>
> I'm agnostic as to the open-ending of the generated vcl-config. It's
> ike
> a nice idea and seems to be the recommended approach from reading the
> varnish docs, but it does seem to hide some complexity.
>
> Regardless, I think we need to solve this issue of caching requests
> with
> cookies, the current behaviour is largely useless for a Plone site.
>
> --
> plone.recipe.varnish does not cache any requests with cookies
> https://bugs.launchpad.net/bugs/276894
> You received this bug notification because you are a direct subscriber
> of the bug.
>
> Status in Collective zc.buildout recipes: New
>
> Bug description:
> I'm using varnish 2.0-beta2 with plone.recipe.varnish 1.0rc6. I have
> mod_proxy_balancer setup to use sticky sessions cookie generate by
> mod_headers with:
>
> Header add Set-Cookie "__balancer_zopes=route.%
> {BALANCER_WORKER_ROUTE}e; path=/;" env=BALANCER_ROUTE_CHANGED
>
> The result is that no pages get cached at all, as there is always a
> Cookie header in the request. Presumably this observation would also
> hold true for all logged in users too with the __ac cookie even
> without the stickysession cookies, or users with the google
> analytics __utm. cookies.
>
> To fix this I had to customise the vcl. Ideally I would have liked
> to ignore only double underscore cookies, but I couldn't quite work
> out how.
>
> I think this would be safe for the default CacheSetup configuration,
> though it may cause problems if you want to cache html pages. Maybe
> for that case there should be some more logic in a sub vcl_hit to
> force a pass if the content type is text/html and the user is
> authenticated.
>
> Index: varnish.vcl
> ===================================================================
> --- varnish.vcl (revision 690)
> +++ varnish.vcl (working copy)
> @@ -30,6 +30,14 @@
> if (req.http.If-None-Match) {
> pass;
> }
> +
> + # ignore cookies starting with underscore
> + if (req.request == "GET" && !(req.http.Authorization) &&
> req.http.cookie) {
> + if (req.http.cookie ~ "(^| )[^_](.+?)($|;)") {
> + pass;
> + }
> + lookup;
> + }
> }
>
> sub vcl_pipe {

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.