<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi,<div><br></div><div>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.</div><div><br></div><div>I'm accessing my solution by</div><div><br></div><div><a href="https://<server>?mobile_redirect=0">https://<server>?mobile_redirect=0</a></div><div><br></div><div><br></div><div>rutine to check user agent</div><div><br></div><div><div>sub detect_device {</div><div>    if ((req.http.User-Agent ~ "iP(hone|od|ad)" || req.http.User-Agent ~ "Android" || req.http.User-Agent ~ "SymbianOS" || req.http.User-Agent ~ "HTC" ||</div><div>        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" ||</div><div>        req.http.User-Agent ~ "SAMSUNG" || req.http.User-Agent ~ "LG")) {</div><div>      set req.http.X-Device = "smart";</div><div>    }</div><div>}</div></div><div><br></div><div><br></div><div>in vcl_recv I have</div><div><br></div><div><div>if (req.http.X-Device == "smart") {</div><div>                if ((req.url ~ "^/client/$") || (req.url ~ "^/client/index.html") || (req.url ~ "^/$") || (req.url ~ "^/")) {</div><div>                  if ((req.url !~ "(.*)(mobile_redirect=0)") && (req.http.Cookie !~ "nomobile=1")) {</div><div>                        error 707 "Redirected to mobile site";</div><div>                  }</div><div>                }</div><div>  }</div></div><div><br></div><div>in vcl_fetch I have</div><div><br></div><div><div>if (req.http.X-Device == "smart") {</div><div>                if (req.url ~ "(.*)(mobile_redirect=0)") {</div><div>                        set beresp.http.Set-Cookie = "nomobile=1; expires: Session; path=/; domain=.";</div><div>                }</div><div>        }</div></div><div><br></div><div>in vcl_error I have</div><div><br></div><div><div>#Mobile User-Agents are send to Mobilesolution</div><div>        if (obj.status == 707) {</div><div>                set obj.status = 302;</div><div>                set obj.http.Location = "https://<mobile-server></div><div>                return(deliver);</div><div>        }</div></div><div><br></div><div><br></div><div>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)</div><div><br></div><div><div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap; font-family: 'Lucida Grande', sans-serif; font-size: 11px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">Set-Cookie:</div><div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; font-size: 11px; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">nomobile=1; expires: Session; path=/; domain=.</div></div><div><div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; font-size: 11px; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "><br></div></div><div><div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; font-size: 11px; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">This seems to be correct. So now I call</div></div><div><div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; font-size: 11px; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "><br></div></div><div><div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; font-size: 11px; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "><span class="Apple-style-span" style="font-family: Helvetica; white-space: normal; -webkit-text-size-adjust: auto; font-size: medium; ">https://<server></span></div></div><div><div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; font-size: 11px; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "><span class="Apple-style-span" style="font-family: Helvetica; white-space: normal; -webkit-text-size-adjust: auto; font-size: medium; "><br></span></div></div><div><div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; font-size: 11px; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "><span class="Apple-style-span" style="font-family: Helvetica; white-space: normal; -webkit-text-size-adjust: auto; font-size: medium; ">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 ?</span></div></div><div><div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; font-size: 11px; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "><span class="Apple-style-span" style="font-family: Helvetica; white-space: normal; -webkit-text-size-adjust: auto; font-size: medium; "><br></span></div></div><div><div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; font-size: 11px; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "><span class="Apple-style-span" style="font-family: Helvetica; white-space: normal; -webkit-text-size-adjust: auto; font-size: medium; ">Any ideas ?</span></div></div><div><div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; font-size: 11px; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "><span class="Apple-style-span" style="font-family: Helvetica; white-space: normal; -webkit-text-size-adjust: auto; font-size: medium; "><br></span></div></div><div><div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; font-size: 11px; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "><span class="Apple-style-span" style="font-family: Helvetica; white-space: normal; -webkit-text-size-adjust: auto; font-size: medium; ">kind regards </span></div></div><div><div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; font-size: 11px; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "><span class="Apple-style-span" style="font-family: Helvetica; white-space: normal; -webkit-text-size-adjust: auto; font-size: medium; "><br></span></div></div><div><div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; font-size: 11px; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "><span class="Apple-style-span" style="font-family: Helvetica; white-space: normal; -webkit-text-size-adjust: auto; font-size: medium; "> Torben</span></div></div><div><div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; font-size: 11px; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "><span class="Apple-style-span" style="font-family: Helvetica; white-space: normal; -webkit-text-size-adjust: auto; font-size: medium; "><br></span></div></div><div><div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; font-size: 11px; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "><span class="Apple-style-span" style="font-family: Helvetica; white-space: normal; -webkit-text-size-adjust: auto; font-size: medium; "><br></span></div></div><div><div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; font-size: 11px; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "><br></div></div></body></html>