51Degrees Device Detection Varnish  4.1

A device detection module for Varnish


This example shows how to use 51Degrees on-premise device detection to determine whether a given User-Agent corresponds to a mobile device or not.

This example is available in full on GitHub.

This example requires a local data file. Free data files can be acquired by pulling the submodules under this repository or from the device-detection-data GitHub repository.

The path to the data need to be updated before running the example.

In a Linux environment, the following commands:

$ curl localhost:8080 -I -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36"
$ curl localhost:8080 -I -A "Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C114"

Expected output:

HTTP/1.1 200 OK
X-IsMobile: False
HTTP/1.1 200 OK
X-IsMobile: True
vcl 4.0;
import fiftyonedegrees;
backend default {
.host = "";
.port = "80";
sub vcl_recv {
set req.http.X-IsMobile = fiftyonedegrees.match_single(req.http.user-agent, "IsMobile");
sub vcl_deliver {
set resp.http.X-IsMobile = fiftyonedegrees.match_single(req.http.user-agent, "IsMobile");
sub vcl_init {