Search
Varnish Enterprise

Introduction Installation Upgrading Troubleshooting Changelog Changelog for 6.0.x Changes (Varnish Cache 4.1) Changes (Varnish Cache Plus 4.1) Known Issues Features Backend SSL/TLS Client SSL/TLS termination Cluster In-Process TLS MSE 4 Basic Configuration / Getting Started Configuration Persisted caching Categories Configuration Reference MSE 3.0 Settings mkfs.mse Memory Governor MSE 2.0 NUMA Parallel ESI Backend health counter HTTP/2 Support JSON Logging TCP Only Probes Timeouts Transit Buffer Varnish scoreboard VMODs Accept Accounting ACL (aclplus) ActiveDNS Akamai Connector AWS VCL Body Access & Transformation (xbody) Brotli Cookie Plus (cookieplus) DeviceAtlas DeviceAtlas3 Digest Dynamic backends (goto) Edgestash File Format Geolocation (geoip/mmdb) Header Manipulation (headerplus) HTTP communication (http) Image JSON parsing (json) JWT Key value storage (kvstore) Least connections director (leastconn) Module to control the built-in HTTP2 transport (h2) MSE control (mse) MSE4 control (mse4) Probe Proxy ProxyV2 TLV Attribute Extraction (proxy) Pseudo Random Number Generator Purge (purge/softpurge) Real-time Status (rtstatus) Reverse DNS (resolver) Rewrite S3 VMOD Session Slicer SQLite3 Stale Standard (std) Stat (Prometheus) Strings (str) Synthetic backends (synthbackend) Tag-based invalidation (Ykey/Xkey) TCP configuration (tcp) TLS Total Encryption (crypto) Unified director object (udo) Uniform Resource Identifier (uri) Unix Socket Utilities (unix) URL Plus (urlplus) Utils Vsthrottle

Accept

Description

The accept VMOD sanitizes content negotiations headers, most notably, Accept-Language. As backends can deliver different objects for the same URL based on these headers, it can be necessary to normalize them to avoid object duplication.

The VMOD follows RFC 7231; it evaluates a list of possible candidates and returns a match to the user’s header, if any, according to the quality (the q parameter) specified by the client for each choice.

Note: Varnish already handles the Accept-Encoding header, so you shouldn’t do it in VCL.

Example

import accept;

sub vcl_init {
  # our server can only return html, json, and its default, plain text
  new format = accept.rule("text/plain");
  format.add("text/html");
  format.add("application/json");

  # also, the content is available in english (the default)
  # as well as french
  new lang = accept.rule("en");
  lang.add("fr");
}

sub vcl_recv {
  # only leave one choice for each header
  set req.http.accept = format.filter(req.http.accept);
  set req.http.accept-language = lang.filter(req.http.accept-language);
}

API

rule

OBJECT rule(STRING string)

This creates a new rule object using string as a fallback in case no match is found.

Arguments:

  • string accepts type STRING

Type: Object

Returns: Object.

.add

VOID .add(STRING string)

This is a method of the rule object and adds string to the list of acceptable candidates.

Arguments:

  • string accepts type STRING

Type: Method

Returns: None

.remove

VOID .remove(STRING string)

This method removes string from the list of candidates.

Arguments:

  • string accepts type STRING

Type: Method

Returns: None

.filter

STRING .filter(STRING string)

This processes string and compares it with the list of candidates. The one with the highest quality is returned or, failing that, the fallback string specified at the rule object creation is used.

Arguments:

  • string accepts type STRING

Type: Method

Returns: String

Availability

The accept VMOD is available in Varnish Enterprise version 6.0.1r1 and later.


®Varnish Software, Wallingatan 12, 111 60 Stockholm, Organization nr. 556805-6203