This module provides enhanced variable support for VCL scripts. It compiles for Varnish versions 3 and 4.

There are two kinds of variables: session-specific, which have the lifespan of one HTTP session (connection) and cease to exist when
it is closed, and global, which are shared between all sessions. Session-specific variables are typed, a pair of functions is provided for setting and retrieveng variables od a particular type. For example the function set_duration sets a duration variable, and get_duration retrieves its value:

Special functions are provided for testing if a variable is defined: the defined() function returns true if the variable is defined, and the type_of() function returns the type of the variable.

A special feature of this module are regset() and queryset() functions. The regset() function allows you to parse a string (e.g. a URL or header value) according to a regular expression and to set several variables at once to selected substrings of the input string, optionally converting between different types. For example, the fragment below sets ttl and grace parameters of the object according to the Surrogate-Control header:

The first argument to regset declares a list of variables to be set, along with their types (:d standing for duration) and
values to be assigned (after = signs). The latter use backreferenses to refer to the substrings captured by the regular expression and add the s suffix to each captured string to obtain a valid duration.

To obtain the same effect without variable.regset, one would have to use regsub twice, casting the result explicitly, as shown below:

The queryset() function treats its argument as a HTTP query, and defines variables according to it. For example:

If req.url contained "q=term&n=10&p=5", this call will define three variables: a string variable "q" having the value "term", and two integer variables "n" and "p" with the values 10 and 5 correspondingly.

Return to:

Send suggestions and report system problems to the System administrator.