Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-devicedetect
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-devicedetect
Commits
32b07724
Commit
32b07724
authored
Dec 19, 2014
by
Lasse Karstensen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finalise testcase renumbering.
parent
1af1dca3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
4 deletions
+50
-4
INSTALL.rst
INSTALL.rst
+43
-0
insert-vcl-examples
insert-vcl-examples
+5
-4
71-example1.vtc
tests/71-example1.vtc
+1
-0
72-example2.vtc
tests/72-example2.vtc
+1
-0
73-example3.vtc
tests/73-example3.vtc
+0
-0
No files found.
INSTALL.rst
View file @
32b07724
...
...
@@ -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
...
...
insert-vcl-examples
View file @
32b07724
...
...
@@ -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
"
\n
VCL::
\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
}
...
...
tests/71-example1.vtc
View file @
32b07724
...
...
@@ -36,6 +36,7 @@ varnish v1 -vcl+backend {
set resp.http.Vary = regsub(resp.http.Vary, "X-UA-Device", "User-Agent");
}
}
} -start
client c1 {
...
...
tests/72-example2.vtc
View file @
32b07724
...
...
@@ -29,6 +29,7 @@ varnish v1 -vcl+backend {
set resp.http.Vary = regsub(resp.http.Vary, "X-UA-Device", "User-Agent");
}
}
} -start
client c1 {
...
...
tests/
0
73-example3.vtc
→
tests/73-example3.vtc
View file @
32b07724
File moved
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment