Ubuntu Manpages

vmod_std

Varnish Standard Module

import std

The Varnish standard module contains useful, generic function that don't quite fit in the VCL core, but are still considered very useful to a broad audience.

toupper(STRING s)
String
Converts the string s to upper case.
set beresp.http.x-scream = std.toupper("yes!");

tolower(STRING s)
String
Converts the string s to lower case.
set beresp.http.x-nice = std.tolower("VerY");

set_ip_tos(INT i)
Void
Sets the Type-of-Service flag for the current session. Please note that the TOS flag is not removed by the end of the request so probably want to set it on every request should you utilize it.
if (req.url ~ ^/slow/) {
std.set_ip_tos(0x0);
}


random(REAL a, REAL b)
Real
Returns a random REAL number between a and b.
set beresp.http.x-random-number = std.random(1, 100);

log(STRING string)
Void
Logs string to the shared memory log.
std.log("Something fishy is going on with the vhost " + req.host);

syslog(INT priority, STRING string)
Void
Logs string to syslog marked with priority.
std.syslog( LOG_USER|LOG_ALERT, "There is serious troble");

fileread(STRING filename)
String
Reads a file and returns a string with the content. Please note that it is not recommended to send variables to this function the caching in the function doesn't take this into account. Also, files are not re-read.
set beresp.http.x-served-by = std.fileread("/etc/hostname");

duration(STRING s, DURATION fallback)
Duration
Converts the string s to seconds. s can be quantified with the usual s (seconds), m (minutes), h (hours), d (days) and w (weeks) units. If s fails to parse, fallback will be used.
set beresp.ttl = std.duration("1w", 3600s);

integer(STRING s, INT fallback)
Int
Converts the string s to an integer. If s fails to parse, fallback will be used
if (std.integer(beresp.http.x-foo, 0) > 5) { ... }

collect(HEADER header)
Void
Collapses the header, joining the headers into one.
std.collect(req.http.cookie); This will collapse several Cookie: headers into one, long cookie header.


The Varnish standard module was released along with Varnish Cache 3.0. This manual page was written by Per Buer with help from Martin Blix Grydeland.

This document is licensed under the same licence as Varnish itself. See LICENCE for details.

  • Copyright (c) 2011 Varnish Software

Per Buer