Remove all but specific Set-Cookie headers

Ruslan Sivak russ at vshift.com
Thu Oct 28 00:32:44 CEST 2010


On 10/27/2010 6:10 PM, Ruslan Sivak wrote:
> http://www.varnish-cache.org/trac/wiki/VCLExampleRemovingSomeCookies
>
> sub vcl_recv {
>   if (!req.http.Cookie) {
>     return (pass);
>   }
>   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 == "") {
>         remove req.http.Cookie;
>     }
>     return(lookup);
>    }
> }
>
>
> What would be the equivalent sub vcl_fetch?  This is what I have, but it
> seems to only work for COOKIE1.  I think because the Cookie header comes
> from the browser all in one line, but there are multiple Set-Cookie
> headers. 
>
> sub vcl_fetch {
>   set beresp.ttl=5d;
>   if (beresp.http.set-cookie) {
>     set beresp.http.set-cookie = ";" beresp.http.set-cookie;
>     set beresp.http.set-cookie = regsuball(beresp.http.set-cookie, ";
> +", ";");
>     set beresp.http.set-cookie = regsuball(beresp.http.set-cookie,
> ";(COOKIE1|COOKIE2)=", "; \1=");
>     set beresp.http.set-cookie = regsuball(beresp.http.set-cookie, ";[^
> ][^;]*", "");
>     set beresp.http.set-cookie = regsuball(beresp.http.set-cookie, "^[;
> ]+|[; ]+$", "");
>
>     if (beresp.http.set-cookie == "") {
>         remove beresp.http.set-cookie;
>     }
>     return (deliver);
>    }
> }
>
> Russ
It seems that according to http://www.varnish-cache.org/trac/ticket/432,
you can only access the first Set-Cookie header?  Is this correct?  If
this is true, why is it an enhancement and not a bug?

Russ




More information about the varnish-misc mailing list