VCL-Variables
The complete album#
- Manual section: 7
DESCRIPTION#
This is a list of all variables in the VCL language.
Variable names take the form scope.variable[.index], for instance:
req.url
beresp.http.date
client.ip
Which operations are possible on each variable is described below, often with the shorthand “backend” which covers the vcl_backend_* {} subroutines and “client” which covers the rest, except vcl_init {} and vcl_fini {}.
local, server, remote and client#
These variables describe the network connection between the client and varnishd.
Without PROXY protocol:
client server
remote local
v v
CLIENT ------------ VARNISHD
With PROXY protocol:
client server remote local
v v v v
CLIENT ------------ PROXY ------------ VARNISHD
client.identity
Type: STRING
Readable from: client, backend
Writable from: client
Identification of the client, used to load balance in the client director. Defaults to
client.ipThis variable can be overwritten with more precise information, for instance extracted from a
Cookie:header.
client.ip
Type: IP
Readable from: client, backend
The client’s IP address, either the same as
remote.ipor what the PROXY protocol told us.
server.hostname
Type: STRING
Readable from: all
The host name of the server, as returned by the gethostname(3) system function.
server.identity
Type: STRING
Readable from: all
The identity of the server, as set by the
-iparameter.If an
-iparameter is not passed to varnishd, the return value from gethostname(3) system function will be used.
server.ip
Type: IP
Readable from: client, backend
The IP address of the socket on which the client connection was received, either the same as
local.ipor what the PROXY protocol told us.
remote.ip
Type: IP
Readable from: client, backend
The IP address of the other end of the TCP connection. This can either be the clients IP, or the outgoing IP of a proxy server.
If the connection is a UNIX domain socket, the value will be
0.0.0.0:0
local.endpoint VCL >= 4.1
Type: STRING
Readable from: client, backend
The address of the ‘-a’ socket the session was accepted on.
If the argument was
-a foo=:81this would be “:81”
local.ip
Type: IP
Readable from: client, backend
The IP address (and port number) of the local end of the TCP connection, for instance
192.168.1.1:81If the connection is a UNIX domain socket, the value will be
0.0.0.0:0
local.socket VCL >= 4.1
Type: STRING
Readable from: client, backend
The name of the ‘-a’ socket the session was accepted on.
If the argument was
-a foo=:81this would be “foo”.Note that all ‘-a’ gets a default name on the form
a%dif no name is provided.
req and req_top#
These variables describe the present request, and when ESI:include requests are being processed, req_top points to the request received from the client.
req
Type: HTTP
Readable from: client
The entire request HTTP data structure. Mostly useful for passing to VMODs.
req.backend_hint
Type: BACKEND
Readable from: client
Writable from: client
Set bereq.backend to this if we attempt to fetch. When set to a director, reading this variable returns an actual backend if the director has resolved immediately, or the director otherwise. When used in string context, returns the name of the director or backend, respectively.
req.can_gzip
Type: BOOL
Readable from: client
True if the client provided
gziporx-gzipin theAccept-Encodingheader.
req.esi VCL <= 4.0
Type: BOOL
Readable from: client
Writable from: client
Set to
falseto disable ESI processing regardless of any value in beresp.do_esi. Defaults totrue. This variable is replaced byresp.do_esiin VCL 4.1.
req.esi_level
Type: INT
Readable from: client
A count of how many levels of ESI requests we’re currently at.
req.filters
Type: STRING
Readable from: vcl_recv
Writable from: vcl_recv
List of Varnish Fetch Processor (VFP) filters the req.body will be pulled through. The order left to right signifies processing from client to cache, iow the leftmost filter is run first on the body as received from the client after decoding of any transfer encodings.
VFP Filters change the body before potentially being cached (e.g. using
std.cache_req.body()) and/or being handled by the backend side, where it may get processed again by bereq.filters.Trying to set req.filters after processing the request body (again, for example with
std.cache_req.body()) triggers a VCL error.
req.grace
Type: DURATION
Readable from: client
Writable from: client
Unsettable from: client
Upper limit on the object grace.
During lookup the minimum of req.grace and the object’s stored grace value will be used as the object’s grace.
When reading the unset value, it is returned as -1.
req.hash
Type: BLOB
Readable from: vcl_hit, vcl_miss, vcl_pass, vcl_purge, vcl_deliver, vcl_synth, vcl_pipe
The hash key of this request. Mostly useful for passing to VMODs, but can also be useful for debugging hit/miss status.
req.hash_always_miss
Type: BOOL
Readable from: client
Writable from: client
Default:
false.Force a cache miss for this request, even if perfectly good matching objects are in the cache.
This is useful to force-update the cache without invalidating existing entries in case the fetch fails.
req.hash_ignore_busy
Type: BOOL
Readable from: client
Writable from: client
Default:
false.Ignore any busy object during cache lookup.
You only want to do this when you have two server looking up content sideways from each other to avoid deadlocks.
req.hash_ignore_vary
Type: BOOL
Readable from: client
Writable from: client
Default:
false.Ignore objects vary headers during cache lookup.
This returns the very first match regardless of the object compatibility with the client request. This is useful when variants are irrelevant to certain clients, and differences in the way the resource is presented don’t change how the client will interpret it.
Use with caution.
req.http.*
Type: HEADER
Readable from: client
Writable from: client
Unsettable from: client
The headers of request, things like
req.http.date.The RFCs allow multiple headers with the same name, and both
setandunsetwill remove all headers with the name given.The header name
*is a VCL symbol and as such cannot, for example, start with a numeral. To work with valid header that can’t be represented as VCL symbols it is possible to quote the name, likereq.http."grammatically.valid". None of the HTTP headers present in IANA registries need to be quoted, so the quoted syntax is discouraged but available for interoperability.Some headers that cannot be tampered with for proper HTTP fetch or delivery are read-only.
req.http.content-length
Type: HEADER
Readable from: client
The content-length header field is protected, see protected_headers.
req.http.transfer-encoding
Type: HEADER
Readable from: client
The transfer-encoding header field is protected, see protected_headers.
req.is_hitmiss
Type: BOOL
Readable from: vcl_miss, vcl_deliver, vcl_pass, vcl_synth
If this request resulted in a hitmiss
req.is_hitpass
Type: BOOL
Readable from: vcl_pass, vcl_deliver, vcl_synth
If this request resulted in a hitpass
req.method
Type: STRING
Readable from: client
Writable from: client
The request method (e.g. “GET”, “HEAD”, …)
req.proto VCL <= 4.0
Type: STRING
Readable from: client
Writable from: client
The HTTP protocol version used by the client, usually “HTTP/1.1” or “HTTP/2.0”.
req.proto VCL >= 4.1
Type: STRING
Readable from: client
The HTTP protocol version used by the client, usually “HTTP/1.1” or “HTTP/2.0”.
req.restarts
Type: INT
Readable from: client
A count of how many times this request has been restarted.
req.storage
Type: STEVEDORE
Readable from: client
Writable from: client
The storage backend to use to save this request body.
req.time
Type: TIME
Readable from: client
The time when the request was fully received, remains constant across restarts.
req.trace
Type: BOOL
Readable from: client
Writable from: client
Controls if
VCL_traceVSL records are emitted for the current request, see VSL.Defaults to the setting of the
feature traceparameter, see varnishd. Does not get reset by a rollback.
req.transport
Type: STRING
Readable from: client
The transport protocol which brought this request.
req.max_age
Type: DURATION
Readable from: client
Writable from: client
Unsettable from: client
Upper limit on the object age for cache lookups to return hit. Matches
Cache-Control: max-agerequest header semantics.When reading the unset value, it is returned as -1.
req.ttl
Type: DURATION
Readable from: client
Writable from: client
Unsettable from: client
Deprecated alias of
req.max-age, which will be removed in a future version of Vinyl-Cache.
req.url
Type: STRING
Readable from: client
Writable from: client
The requested URL, for instance “/robots.txt”.
req.xid
Type: INT
Readable from: client
Unique ID of this request.
req_top.http.*
Type: HEADER
Readable from: client
HTTP headers of the top-level request in a tree of ESI requests. Identical to req.http. in non-ESI requests.
See req.http for general notes.
req_top.method
Type: STRING
Readable from: client
The request method of the top-level request in a tree of ESI requests. (e.g. “GET”, “HEAD”). Identical to req.method in non-ESI requests.
req_top.proto
Type: STRING
Readable from: client
HTTP protocol version of the top-level request in a tree of ESI requests. Identical to req.proto in non-ESI requests.
req_top.time
Type: TIME
Readable from: client
The time when the top-level request was fully received, remains constant across restarts.
req_top.url
Type: STRING
Readable from: client
The requested URL of the top-level request in a tree of ESI requests. Identical to req.url in non-ESI requests.
bereq#
This is the request we send to the backend, it is built from the clients req.* fields by filtering out “per-hop” fields which should not be passed along (Connection:, Range: and similar).
Slightly more fields are allowed through for pass fetches than for miss fetches, for instance `Range.
bereq
Type: HTTP
Readable from: backend
The entire backend request HTTP data structure. Mostly useful as argument to VMODs.
bereq.backend
Type: BACKEND
Readable from: vcl_pipe, backend
Writable from: vcl_pipe, backend
This is the backend or director we attempt to fetch from. When set to a director, reading this variable returns an actual backend if the director has resolved immediately, or the director otherwise. When used in string context, returns the name of the director or backend, respectively.
bereq.between_bytes_timeout
Type: DURATION
Readable from: backend
Writable from: backend
Unsettable from: vcl_pipe, backend
Default:
.between_bytes_timeoutattribute from the Backend definition, which defaults to thebetween_bytes_timeoutparameter, see varnishd.The time in seconds to wait between each received byte from the backend. Not available in pipe mode.
bereq.body
Type: BODY
Unsettable from: vcl_backend_fetch
The request body.
Unset will also remove bereq.http.content-length.
bereq.connect_timeout
Type: DURATION
Readable from: vcl_pipe, backend
Writable from: vcl_pipe, backend
Unsettable from: vcl_pipe, backend
Default:
.connect_timeoutattribute from the Backend definition, which defaults to theconnect_timeoutparameter, see varnishd.The time in seconds to wait for a backend connection to be established.
bereq.filters
Type: STRING
Readable from: vcl_backend_fetch
Writable from: vcl_backend_fetch
List of VDP filters the bereq.body will be pushed through when sending the body to the backend.
bereq.first_byte_timeout
Type: DURATION
Readable from: backend
Writable from: backend
Unsettable from: vcl_pipe, backend
Default:
.first_byte_timeoutattribute from the Backend definition, which defaults to thefirst_byte_timeoutparameter, see varnishd.The time in seconds to wait getting the first byte back from the backend. Not available in pipe mode.
bereq.hash
Type: BLOB
Readable from: vcl_pipe, backend
The hash key of this request, a copy of
req.hash.
bereq.http.*
Type: HEADER
Readable from: vcl_pipe, backend
Writable from: vcl_pipe, backend
Unsettable from: vcl_pipe, backend
The headers to be sent to the backend.
See req.http for general notes.
bereq.http.content-length
Type: HEADER
Readable from: backend
The content-length header field is protected, see protected_headers.
bereq.http.transfer-encoding
Type: HEADER
Readable from: backend
The transfer-encoding header field is protected, see protected_headers.
bereq.is_bgfetch
Type: BOOL
Readable from: backend
True for fetches where the client got a hit on an object in grace, and this fetch was kicked of in the background to get a fresh copy.
bereq.is_hitmiss
Type: BOOL
Readable from: backend
If this backend request was caused by a hitmiss.
bereq.is_hitpass
Type: BOOL
Readable from: backend
If this backend request was caused by a hitpass.
bereq.method
Type: STRING
Readable from: vcl_pipe, backend
Writable from: vcl_pipe, backend
The request type (e.g. “GET”, “HEAD”).
Regular (non-pipe, non-pass) fetches are always “GET”
bereq.proto VCL <= 4.0
Type: STRING
Readable from: vcl_pipe, backend
Writable from: vcl_pipe, backend
The HTTP protocol version, “HTTP/1.1” unless a pass or pipe request has “HTTP/1.0” in
req.proto
bereq.proto VCL >= 4.1
Type: STRING
Readable from: vcl_pipe, backend
The HTTP protocol version, “HTTP/1.1” unless a pass or pipe request has “HTTP/1.0” in
req.proto
bereq.retries
Type: INT
Readable from: backend
A count of how many times this request has been retried.
bereq.retry_connect
Type: BOOL
Readable from: backend
Writable from: backend
Default:
true. Controls whether Varnish will make a second attempt to connect to the backend if a first connection reuse attempt failed. Setting tofalsemeans that no retries will be made. However, setting this totruedoes not guarantee that a retry will always be attempted, as there are other factors involved in the decision (ex: a request body not being cached). Note that this only controls automatic retries due to connection failures, and does not affect retries initiated from VCL usingreturn(retry);.
