Manual section: | 3 |
---|
import std [from "path"] ;
STRING toupper(STRING s)
STRING tolower(STRING s)
VOID set_ip_tos(INT tos)
REAL random(REAL lo, REAL hi)
VOID log(STRING s)
VOID syslog(INT priority, STRING s)
STRING fileread(STRING)
BOOL file_exists(STRING path)
VOID collect(HEADER hdr, STRING sep)
DURATION duration(STRING s, DURATION fallback)
INT integer(STRING s, INT fallback)
IP ip(STRING s, IP fallback, BOOL resolve)
REAL real(STRING s, REAL fallback)
INT real2integer(REAL r, INT fallback)
TIME real2time(REAL r, TIME fallback)
INT time2integer(TIME t, INT fallback)
REAL time2real(TIME t, REAL fallback)
BOOL healthy(BACKEND be)
INT port(IP ip)
VOID rollback(HTTP h)
VOID timestamp(STRING s)
STRING querysort(STRING)
BOOL cache_req_body(BYTES size)
STRING strstr(STRING s1, STRING s2)
TIME time(STRING s, TIME fallback)
STRING getenv(STRING name)
VOID late_100_continue(BOOL late)
BOOL syntax(REAL)
vmod_std contains basic functions which are part and parcel of Varnish, but which for reasons of architecture fit better in a VMOD.
One particular class of functions in vmod_std is the conversions functions which all have the form:
TYPE type(STRING, TYPE)
These functions attempt to convert STRING to the TYPE, and if that fails, they return the second argument, which must have the given TYPE.
Logs the string s to syslog tagged with priority. priority is formed by ORing the facility and level values. See your system's syslog.h file for possible values.
Notice: Unlike VCL and other functions in the std vmod, this function will not fail VCL processing for workspace overflows: For an out of workspace condition, the syslog() function has no effect.
std.syslog(9, "Something is wrong");
This will send a message to syslog using LOG_USER | LOG_ALERT.
Consider that the entire contents of the file appear in the string that is returned, including newlines that may result in invalid headers if std.fileread() is used to form a header. In that case, you may need to modify the string, for example with regsub():
set beresp.http.served-by = regsub(std.fileread("/etc/hostname"), "\R$", "");
Collapses multiple hdr headers into one long header. The default separator sep is the standard comma separator to use when collapsing headers, with an additional whitespace for pretty printing.
Care should be taken when collapsing headers. In particular collapsing Set-Cookie will lead to unexpected results on the browser side.
Converts the string s to the first IP number returned by the system library function getaddrinfo(3). If conversion fails, fallback will be returned.
If resolve is false, getaddrinfo() is called using AI_NUMERICHOST to avoid network lookups. This makes "pure" IP strings cheaper to convert.
Caches the request body if it is smaller than size. Returns true if the body was cached, false otherwise.
Normally the request body is not available after sending it to the backend. By caching it is possible to retry pass operations, e.g. POST and PUT.
Returns a string beginning at the first occurrence of the string s2 in the string s1, or an empty string if s2 is not found.
Note that the comparison is case sensitive.
This will check if the content of req.http.restrict occurs anywhere in req.url.
Converts the string s to a time. If conversion fails, fallback will be returned.
Supported formats:
Return environment variable name or the empty string.
See getenv(3)
Controls when varnish reacts to an Expect: 100-continue client request header.
Varnish always generates a 100 Continue response if requested by the client trough the Expect: 100-continue header when waiting for request body data.
But, by default, the 100 Continue response is already generated immediately after vcl_recv returns to reduce latencies under the assumption that the request body will be read eventually.
Calling std.late_100_continue(true) in vcl_recv will cause the 100 Continue response to only be sent when needed. This may cause additional latencies for processing request bodies, but is the correct behavior by strict interpretation of RFC7231.
This function has no effect outside vcl_recv and after calling std.cache_req_body() or any other function consuming the request body.
Copyright (c) 2010-2017 Varnish Software AS
All rights reserved.
Author: Poul-Henning Kamp <phk@FreeBSD.org>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.