A utility for parsing User-Agent strings in Fastly VCL, based on ua-parser/uap-core.
- Copy
useragent-parser.vcl - Include it in your
main.vcl-
include "useragent-parser.vcl";
-
- To get user-agent information, call
get_parsed_useragent- The return value is a Dict type of Structure Field Values; use the
subfieldfunction to retrieve specific values -
declare local var.useragent STRING; set var.useragent = get_parsed_useragent(); set req.http.User-Agent-Family = subfield(var.useragent, "family"); set req.http.User-Agent-Version = subfield(var.useragent, "major") "." subfield(var.useragent, "minor") "." subfield(var.useragent, "patch");
- The return value is a Dict type of Structure Field Values; use the
- To get OS information, call
get_useragent_os- The return value is a Dict type of Structure Field Values; use the
subfieldfunction to retrieve specific values -
declare local var.os STRING; set var.os = get_useragent_os(); set req.http.User-Agent-OS = subfield(var.os, "family");
- The return value is a Dict type of Structure Field Values; use the
- To get device information, call
get_useragent_device- The return value is a Dict type of Structure Field Values; use the
subfieldfunction to retrieve specific values -
declare local var.device STRING; set var.device = get_useragent_device(); set req.http.User-Agent-Device = subfield(var.device, "family");
- The return value is a Dict type of Structure Field Values; use the
Returns the parsed user-agent result.
For details, see ua-parser/uap-core - docs/specification.md - user_agent_parsers.
| Key | |
|---|---|
family |
User-agent family name |
major |
Major version |
minor |
Minor version |
patch |
Patch version |
Returns OS information inferred from the user-agent.
For details, see ua-parser/uap-core - docs/specification.md - os_parsers.
| Key | |
|---|---|
family |
Common name of the OS |
major |
Major version |
minor |
Minor version |
patch |
Patch version |
patchMinor |
Patch minor version |
Returns device information inferred from the user-agent.
For details, see ua-parser/uap-core - docs/specification.md - device_parsers.
| Key | |
|---|---|
family |
Common name of the device |
brand |
Brand name |
model |
Model name |