Varnish subroutine to detect device (mobile, tablet and desktop)
git clone http://git.thebigbrainscompany.com/borisguery/varnish-device-detect.git varnish/routines/folder/or/whatever
Varnish subroutines are a really simple way to somewhat modularize your VCL, they are actually not functions as they don't take arguments nor they return anything.
To make use of this subroutine, you have to call it from inside the vcl_recv
subroutine. It will set two new header in the req
object which allow you to conditionally work
with it.
include "routines/devicedetect.vcl";
sub vcl_recv {
call devicedetect;
if (req.http.X-UA-Device-Type == "mobile") {
error 701 regsub(req.http.host, "^www\.(.*)", "http://mobile.\1") + req.url; //Capture everything after the www. and place it after a http://
}
}
sub vcl_error {
// Redirect to mobile host
if (obj.status == 701) {
set obj.http.Location = obj.response;
set obj.status = 302;
return(deliver);
}
}
make test
- Take a look at the list of issues.
- Fork
- Write a test (for either new feature or bug)
- Make a PR
- Varnish 3.x
- Python 2.x
- Boris Guéry <guery.b@gmail.com> - http://borisguery.com - @borisguery
Varnish Device Dectect
is licensed under the MIT License - see the LICENSE file for details