Commit 32b07724 authored by Lasse Karstensen's avatar Lasse Karstensen

Finalise testcase renumbering.

parent 1af1dca3
......@@ -59,6 +59,7 @@ VCL::
set resp.http.Vary = regsub(resp.http.Vary, "X-UA-Device", "User-Agent");
}
}
.. 71-example1-end
......@@ -108,6 +109,7 @@ VCL::
set resp.http.Vary = regsub(resp.http.Vary, "X-UA-Device", "User-Agent");
}
}
.. 72-example2-end
Example 3: Add the device class as a GET query parameter
......@@ -123,6 +125,47 @@ The client itself does not see this classification, only the backend request is
VCL::
include "devicedetect.vcl";
sub vcl_recv { call devicedetect; }
# do this after vcl_hash, so all Vary-ants can be purged in one go. (avoid ban()ing)
sub vcl_backend_fetch {
if ((bereq.http.X-UA-Device) && (bereq.method == "GET")) {
# if there are existing GET arguments;
if (bereq.url ~ "\?") {
set bereq.http.X-get-devicetype = "&devicetype=" + bereq.http.X-UA-Device;
} else {
set bereq.http.X-get-devicetype = "?devicetype=" + bereq.http.X-UA-Device;
}
set bereq.url = bereq.url + bereq.http.X-get-devicetype;
unset bereq.http.X-get-devicetype;
}
}
# Handle redirects, otherwise standard Vary handling code from previous examples.
sub vcl_backend_response {
if (bereq.http.X-UA-Device) {
if (!beresp.http.Vary) { # no Vary at all
set beresp.http.Vary = "X-UA-Device";
} elseif (beresp.http.Vary !~ "X-UA-Device") { # add to existing Vary
set beresp.http.Vary = beresp.http.Vary + ", X-UA-Device";
}
# if the backend returns a redirect (think missing trailing slash), we
# will potentially show the extra address to the client. we don't want that.
# if the backend reorders the get parameters, you may need to be smarter here. (? and & ordering)
if (beresp.status == 301 || beresp.status == 302 || beresp.status == 303) {
set beresp.http.Location = regsub(beresp.http.location, "[?&]devicetype=.*$", "");
}
}
set beresp.http.X-UA-Device = bereq.http.X-UA-Device;
}
sub vcl_deliver {
if ((req.http.X-UA-Device) && (resp.http.Vary)) {
set resp.http.Vary = regsub(resp.http.Vary, "X-UA-Device", "User-Agent");
}
}
.. 73-example3-end
Different backend for mobile clients
......
......@@ -5,6 +5,7 @@
#
tmpfile=/tmp/foo$RANDOM
DOCUMENT=INSTALL.rst
transform() {
f=$1
......@@ -13,10 +14,10 @@ transform() {
sed -i 's/${projectdir}\/..\///' $tmpfile
# remove first and last line of file. todo: learn more sed to do this more smoothly.
tail -n+2 $tmpfile | head -n-1 > $tmpfile.2; mv $tmpfile.2 $tmpfile
sed -e "/.. $f-start/ q" INSTALL.rst > $tmpfile.orig.top
echo -e "VCL::\n" >> $tmpfile.orig.top
sed -n "/.. $f-end/,\$p" INSTALL.rst >$tmpfile.orig.below
cat $tmpfile.orig.top $tmpfile $tmpfile.orig.below > INSTALL.rst
sed -e "/.. $f-start/ q" $DOCUMENT > $tmpfile.orig.top
echo -e "\nVCL::\n" >> $tmpfile.orig.top
sed -n "/.. $f-end/,\$p" $DOCUMENT >$tmpfile.orig.below
cat $tmpfile.orig.top $tmpfile $tmpfile.orig.below > $DOCUMENT
rm $tmpfile $tmpfile.orig.top $tmpfile.orig.below
}
......
......@@ -36,6 +36,7 @@ varnish v1 -vcl+backend {
set resp.http.Vary = regsub(resp.http.Vary, "X-UA-Device", "User-Agent");
}
}
} -start
client c1 {
......
......@@ -29,6 +29,7 @@ varnish v1 -vcl+backend {
set resp.http.Vary = regsub(resp.http.Vary, "X-UA-Device", "User-Agent");
}
}
} -start
client c1 {
......
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