Set cookie creating issues

Pinakee BIswas pinakee at waltzz.com
Fri Apr 27 14:57:01 UTC 2018


Hi,

We have been using Varnish for caching our web pages. We have an 
ecommerce site. Things have been working fine till today but suddenly 
things have started breaking down and I am not sure why. Following is 
the issue:

We use session cookie to store user sessions. The session cookie is 
getting changed as Cached responses from varnish is having set-cookie 
header which is messing up the session cookie. We are using varnish 4.8. 
Following is a snippet of the VCL:


sub vcl_recv {
     # Happens before we check if we have this in cache already.
     #
     # Typically you clean up the request here, removing cookies you 
don't need,
     # rewriting the request, etc.
     set req.backend_hint = uwsgi;

     #if (req.http.cookie ~ "jivaana_country=") {
         # Set the country header
#       set req.http.X-CLIENT-COUNTRY = regsub(req.http.cookie, 
".*jivaana_country=([^;]+);.*", "\1");
#    }

    std.log("ga:" + ga.extract(req.url, mode = keep));
    set req.url = ga.apply(req.url); #  remove Google Analytics parameters

    if (req.method == "GET") {
         if ((req.url !~ "^/accounts/userheader") &&
             (req.url !~ "^/accounts/new-userheader") &&
             (req.url !~ "^/product/recently-viewed") &&
             (req.url !~ "^/product/recommended-products") &&
             (req.url !~ "^/product/addtobasket")) {
                 unset req.http.cookie; # strip the cookies - we don't 
need them
         }
     }

     call devicedetect;
}

sub vcl_backend_response {
     # Happens after we have read the response headers from the backend.
     #
     # Here you clean the response headers, removing silly Set-Cookie 
headers
     # and other mistakes your backend does.
     if (bereq.method == "GET") {
         set beresp.do_esi = true;
         if ((bereq.url !~ "^/accounts/userheader") &&
             (bereq.url !~ "^/accounts/new-userheader") &&
             (bereq.url !~ "^/product/recently-viewed") &&
             (bereq.url !~ "^/product/recommended-products") &&
             (bereq.url !~ "^/product/addtobasket")) {
                 #unset beresp.http.Set-Cookie;
                 set beresp.uncacheable = false;
                 #std.log("Caching the url : **********************" + 
bereq.url);
    }
}

sub vcl_deliver {
     # Happens when we have all the pieces we need, and are about to 
send the
     # response to the client.
     #
     # You can do accounting or modifying the final object here.
}

sub vcl_hash {
}

Would really appreciate any support as this is messing up our user sessions.

Thanks,

Pinakee



More information about the varnish-misc mailing list