Can Varnish Set Cookies?

Jim Hayter jhayter at
Fri Nov 18 21:55:40 CET 2011

Travis wrote:
 > Sorry if this is on the ineternet somewhere, but I have yet to find it.

 > Can Varnish set a cookie?

> In example, if a user on a mobile device goes to, Varnish sees a 
> mobile user agent and redirects them to via the vcl_error 
> section.  Before or after the redirect, can Varnish set a cookie without 
> the application doing so?

> Thanks,
> Travis

I'm running varnish 2.0.5 but would not expect the syntax to have changed much.
The obj part may no longer be what is used, I believe the current versions use beresp.

I use the code below in vcl_fetch.
   If (test for setting cookie) {
	set obj.http.Set-Cookie = "use_mobile_dev=yes; domain=.<xxxxxxxx>.com; path=/";

This works for the limited case where I need it.  I don't remember the impact if any 
Set-Cookie headers already exist.


More information about the varnish-misc mailing list