Cookie set on beresp not present on next request

Torben Pedersen torbped at gmail.com
Tue May 8 13:00:26 CEST 2012


Hi,

I'm trying to use Varnish + a cookie to control access from mobile devices. I've seen other people doing similar, but I can't get it to work.

I'm accessing my solution by

https://<server>?mobile_redirect=0


rutine to check user agent

sub detect_device {
    if ((req.http.User-Agent ~ "iP(hone|od|ad)" || req.http.User-Agent ~ "Android" || req.http.User-Agent ~ "SymbianOS" || req.http.User-Agent ~ "HTC" ||
        req.http.User-Agent ~ "BlackBerry" || req.http.User-Agent ~ "SonyEricsson" || req.http.User-Agent ~ "Nokia" || req.http.User-Agent ~ "NOKIA" || req.http.User-Agent ~"IEMobile" ||
        req.http.User-Agent ~ "SAMSUNG" || req.http.User-Agent ~ "LG")) {
      set req.http.X-Device = "smart";
    }
}


in vcl_recv I have

if (req.http.X-Device == "smart") {
                if ((req.url ~ "^/client/$") || (req.url ~ "^/client/index.html") || (req.url ~ "^/$") || (req.url ~ "^/")) {
                  if ((req.url !~ "(.*)(mobile_redirect=0)") && (req.http.Cookie !~ "nomobile=1")) {
                        error 707 "Redirected to mobile site";
                  }
                }
  }

in vcl_fetch I have

if (req.http.X-Device == "smart") {
                if (req.url ~ "(.*)(mobile_redirect=0)") {
                        set beresp.http.Set-Cookie = "nomobile=1; expires: Session; path=/; domain=.";
                }
        }

in vcl_error I have

#Mobile User-Agents are send to Mobilesolution
        if (obj.status == 707) {
                set obj.status = 302;
                set obj.http.Location = "https://<mobile-server>
                return(deliver);
        }


So on first request to https://<server>?mobile_redirect=0 , I can se in Chrome (Response headers)  - I've set Chrome to act as an Android (Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; Nexus S Build/GRK39F) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1)

Set-Cookie:nomobile=1; expires: Session; path=/; domain=.

This seems to be correct. So now I call

https://<server>

And I expect not to get redirected since the Set-Cookie is present. But the nomobile=1 is not present in request / Cookie. I don't quite get why ?

Any ideas ?

kind regards 

 Torben



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20120508/00c9d28d/attachment.html>


More information about the varnish-misc mailing list