uap-vcl is a VCL module which parses a User-Agent string. It returns
the user agent family, major version, minor version and patch version.
Why do this in VCL? This module follows the same rules as ua-parser, an open-source and community-driven, regexp-based user-agent parser. It has been ported to many different programming languages all of which share the same parser.
If you are already using a ua-parser-based parser on your origin then this module provides an easy migration path to moving User-Agent-based logic to VCL.
You can view the output for your current browser as HTML at: https://uap-vcl.freetls.fastly.net/
Or as JSON using:
$ curl https://uap-vcl.freetls.fastly.net/ -Haccept:application/json
{
"ua_family": "curl",
"ua_major": "7",
"ua_minor": "50",
"ua_patch": "3"
}
The module consists of a library, uap.vcl which you can include in your Fastly service.
This sets the following variables:
req.http.ua_family
req.http.ua_major
req.http.ua_minor
req.http.ua_patchFor example, it might return the following:
ua_family: "Chrome"
ua_major: "67"
ua_minor: "0"
ua_patch: "3396"Not all variables are set for every user agent. For example, Firefox might show:
ua_family: "Firefox"
ua_major: "60"
ua_minor: "0"
ua_patch: "null"This works by parsing the ua-parser ruleset and generating VCL which follows its matching rules. It also includes a full test suite from ua-parser.
You should have access to the Fastly GitHub organization. Then run:
$ git clone git@github.com:fastly/uap-vcl.git
Cloning into 'uap-vcl'...
$ npm install
$ npm run generateThis generates uap.vcl.
Send a pull request, but don't forget to:
$ npm run eslint
$ npm run prettier
$ npm run generate
$ npm run testThis code is available as open source under the terms of the Apache 2 License.
Copyright 2018 Fastly, Inc.
Is this useful? Let me know! Léon Brocard <leon@fastly.com>