djb
djb

Reputation: 6011

How can I selectively strip/allow cookies with Varnish?

I have Varnish set up to strip all cookies thus:

sub vcl_fetch {
    unset beresp.http.Set-Cookie;
    #etc
}

However, I want to set a cookie called first_visit that I don't want Varnish to strip.

How do I do this?

Upvotes: 1

Views: 1269

Answers (2)

NITEMAN
NITEMAN

Reputation: 1236

You can also strip cookies in plain VCL:

sub vcl_fetch {
  # ...
  if ( beresp.http.Set-Cookie 
    && beresp.http.Set-Cookie == "first_visit=Y; path=/; domain=mydomain.tld" 
  ) {
    set beresp.http.first-visit = beresp.http.Set-Cookie;
    unset beresp.http.Set-Cookie;
  }
  # ...
}

sub vcl_deliver {
  # ...
  if (resp.http.first-visit) {
    set resp.http.Set-Cookie = resp.http.first-visit;
    unset resp.http.first-visit;
  }
  # ...
}

Upvotes: 1

ghloogh
ghloogh

Reputation: 1684

You may take a look on Header vmod, it allows manipulations with Set-Cookie

Upvotes: 2

Related Questions