Strange different behavior

Laurence Rowe l at
Fri Jan 15 16:49:13 CET 2010

2010/1/15 Rob S <rtshilston at>:
> Poul-Henning Kamp wrote:
>> You really need to find out what bit of user-agent your backend
>> cares about.  We are talking a multiplication factor of 100-1000 here
> Very slightly off-topic, but is it possible to vary based on a cookie?
> I'd rather leave one of our applications to process the user-agent,
> login credentials etc, than to move that logic into Varnish.

You can do this by extracting the value of a cookie into its own
header, then vary on that. e.g:

sub vcl_recv {
  # We only care about the language in the I18N_LANGUAGE cookie
  if (req.http.Cookie ~ "(^|.*; )I18N_LANGUAGE=") {
    set req.http.Accept-Language = regsub(req.http.Cookie, "(^|.*;
)I18N_LANGUAGE=([^;]*)(; .*|$)", "\2");
    # XXX need to work out the proper way to match " here, e.g. "en"
    set req.http.Accept-Language = regsub(req.http.Accept-Language,
"^.(.*).$", "\1");
  } else {
    set req.http.Accept-Language = "en";


More information about the varnish-misc mailing list