Commit 081ea15a authored by Lasse Karstensen's avatar Lasse Karstensen

doc + support unsetting the override cookie

parent b1ac25e2
#
# devicedetect-dev.vcl
#
# Enable test URLs and cookie overrides
# Enable test URLs and cookie overrides.
#
backend devicetest {
.host = "127.0.0.1";
......@@ -9,17 +10,26 @@ backend devicetest {
}
sub vcl_recv {
if (req.url ~ "^/set_devicetype/") { error 701 regsub(req.url, "^/set_devicetype/", ""); }
if (req.url ~ "^/devicetest") { set backend = devicetest; }
# 701/702 are arbitrary chosen return codes that is only used internally in varnish.
if (req.url ~ "^/set_ua_device/.+") { error 701 regsub(req.url, "^/set_ua_device/", ""); }
# set expired cookie if nothing is specified
if (req.url ~ "^/set_ua_device/") { error 702 "OK"; }
if (req.url ~ "^/devicetest") { set req.backend = devicetest; }
}
sub vcl_error {
if (obj.status == 701 ) {
# obj.response == mobile-generic
set obj.http.Set-Cookie = "X-UA-device=" + obj.response;
set obj.http.Content-Type = "text/plain; charset=utf-8";
synthetic {" 200 OK, Cookie set "};
return(deliver)
if (obj.status == 701 || obj.status == 702) {
if (obj.status == 702) {
set obj.status = 200;
set obj.http.Set-Cookie = "X-UA-Device-force=expiring; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";
} else {
set obj.status = 200;
set obj.http.Set-Cookie = "X-UA-Device-force=" + obj.response + "; Path=/;";
}
set obj.http.Content-Type = "text/html; charset=utf-8";
synthetic {"<html><body><h1>OK, Cookie updated</h1><a href='/devicetest/'>/devicetest/</a></body></html>"};
set obj.response = "OK";
return(deliver);
}
}
"""
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment