varnish-devicedetect lets me return different responses based on User-agent:
...
elsif (req.http.User-Agent ~ "(?i)ipad") { set req.http.X-UA-Device = "tablet-ipad"; }
elsif (req.http.User-Agent ~ "(?i)ip(hone|od)") { set req.http.X-UA-Device = "mobile-iphone"; }
...
and lets users opt into a different device experience by setting a cookie:
if (req.http.Cookie ~ "(?i)X-UA-Device-force") {
...
}
Do I need to add Vary: Cookie
to get correct client caching behavior?
For example:
Vary: User-agent
X-UA-Device-force: pc
.Yes, you need to set a Vary: Cookie
header to get the correct behaviour since different cookies would retrive different output.
You'll need also to take care of the cookie on vcl_recv
setting the appropriate X-UA-Device
in order to hash items correctly in varnish.