Retaining some cookies and receiving hits

sreeranj s sreeranj4droid at gmail.com
Mon May 29 18:15:28 CEST 2017


Hi,

As per the link
https://varnish-cache.org/docs/4.0/users-guide/increasing-your-hitrate.html,
following code will help us to retain COOKIE1 and |COOKIE2, but strip other
cookies. So COOKIE1 and |COOKIE2 is send to backend. I have the following
questions.

1) By default varnish will not cache if there is cookie present in request
or a set-cookie value is there in server response. In the following case we
have retained COOKIE1 and |COOKIE2, but I still have varnish caches the
responses(I have the unset cookie  from backend responses). Could you
please let me know the reason.

2) If the approach is ok, please advise on any issues are related to this
approach.

3) I am not adding any specific value in hash block, so requests are cached
only based on req-url or IP. hope that is right.


=================================

sub vcl_recv {
    if (req.http.Cookie) {
        set req.http.Cookie = ";" + req.http.Cookie;
        set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
        set req.http.Cookie = regsuball(req.http.Cookie,
";(COOKIE1|COOKIE2)=", "; \1=");
        set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
        set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");

        if (req.http.Cookie == "") {
            unset req.http.Cookie;
        }
    }}


=================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20170529/90ac1066/attachment.html>


More information about the varnish-misc mailing list