VCL-Variables·续2
resp.body
Type: BODY
Writable from: vcl_synth
To produce a synthetic response body, for instance for errors.
resp.do_esi VCL >= 4.1
Type: BOOL
Readable from: vcl_deliver, vcl_synth
Writable from: vcl_deliver, vcl_synth
Default: obj.can_esi
This can be used to selectively disable ESI processing, even though ESI parsing happened during fetch (see beresp.do_esi). This is useful when Varnish caches peer with each other.
It is a VCL error to use resp.do_esi after setting resp.filters.
resp.filters
Type: STRING
Readable from: vcl_deliver, vcl_synth
Writable from: vcl_deliver, vcl_synth
List of VDP filters the resp.body will be pushed through.
Before resp.filters is set, the value read will be the default filter list as determined by varnish based on resp.do_esi and request headers.
After resp.filters is set, changing any of the conditions which otherwise determine the filter selection will have no effect. Using resp.do_esi is an error once resp.filters is set.
resp.http.*
Type: HEADER
Readable from: vcl_deliver, vcl_synth
Writable from: vcl_deliver, vcl_synth
Unsettable from: vcl_deliver, vcl_synth
The HTTP headers that will be returned.
See req.http for general notes.
resp.http.content-length
Type: HEADER
Readable from: vcl_deliver, vcl_synth
The content-length header field is protected, see protected_headers.
resp.http.transfer-encoding
Type: HEADER
Readable from: vcl_deliver, vcl_synth
The transfer-encoding header field is protected, see protected_headers.
resp.is_streaming
Type: BOOL
Readable from: vcl_deliver, vcl_synth
Returns true when the response will be streamed while being fetched from the backend.
resp.proto VCL <= 4.0
Type: STRING
Readable from: vcl_deliver, vcl_synth
Writable from: vcl_deliver, vcl_synth
The HTTP protocol version to use for the response.
resp.proto VCL >= 4.1
Type: STRING
Readable from: vcl_deliver, vcl_synth
The HTTP protocol version to use for the response.
resp.reason
Type: STRING
Readable from: vcl_deliver, vcl_synth
Writable from: vcl_deliver, vcl_synth
The HTTP status message that will be returned.
resp.status
Type: INT
Readable from: vcl_deliver, vcl_synth
Writable from: vcl_deliver, vcl_synth
The HTTP status code that will be returned.
More information in the HTTP response status section.
resp.status 200 will get changed into 304 by core code after a return(deliver) from vcl_deliver for conditional requests to cached content if validation succeeds.
For the validation, first
req.http.If-None-Matchis compared againstresp.http.Etag. If they compare equal according to the rules for weak validation (see RFC7232), a 304 is sent.Secondly,
req.http.If-Modified-Sinceis compared againstresp.http.Last-Modifiedor, if it is unset or weak, against the point in time when the object was last modified based on theDateandAgeheaders received with the backend response which created the object. If the object has not been modified based on that comparison, a 304 is sent.
resp.time
Type: TIME
Readable from: vcl_deliver, vcl_synth
The time when we started preparing the response, just before entering
vcl_synth {}orvcl_deliver {}.
Special variables#
now
Type: TIME
Readable from: all
The current time, in seconds since the UNIX epoch.
When converted to STRING in expressions it returns a formatted timestamp like
Tue, 20 Feb 2018 09:30:31 GMT
nowremains stable for the duration of any built-in VCL subroutine to make time-based calculations predictable and avoid edge cases.In other words, even if considerable amounts of time are spent in VCL,
nowwill always represent the point in time when the respective built-in VCL subroutine was entered.nowis thus not suitable for any kind of time measurements. See VOID timestamp(STRING s), TIME now() and DURATION timed_call(SUB) in VMOD std - Varnish Standard Module.
sess#
A session corresponds to the “conversation” that Varnish has with a single client connection, over which one or more request/response transactions may take place. It may comprise the traffic over an HTTP/1 keep-alive connection, or the multiplexed traffic over an HTTP/2 connection.
sess.idle_send_timeout
Type: DURATION
Readable from: client
Writable from: client
Unsettable from: client
Send timeout for individual pieces of data on client connections, defaults to the
idle_send_timeoutparameter, see varnishd
sess.send_timeout
Type: DURATION
Readable from: client
Writable from: client
Unsettable from: client
Total timeout for ordinary HTTP1 responses, defaults to the
send_timeoutparameter, see varnishd
sess.timeout_idle
Type: DURATION
Readable from: client
Writable from: client
Unsettable from: client
Idle timeout for this session, defaults to the
timeout_idleparameter, see varnishd
sess.timeout_linger
Type: DURATION
Readable from: client
Writable from: client
Unsettable from: client
Linger timeout for this session, defaults to the
timeout_lingerparameter, see varnishd
sess.xid VCL >= 4.1
Type: INT
Readable from: client, backend
Unique ID of this session.
storage#
storage..free_space
Type: BYTES
Readable from: client, backend
Default: 0
Free space available in the named stevedore. Only available for the malloc stevedore.
storage..happy
Type: BOOL
Readable from: client, backend
Default: true
Health status for the named stevedore. Not available in any of the current stevedores.
storage..used_space
Type: BYTES
Readable from: client, backend
Default: 0
Used space in the named stevedore. Only available for the malloc stevedore.
Runtime parameters#
Some of the global runtime parameters related to VCL transactions are readable anywhere in VCL. The value of a parameter can change between accesses, it is not cached for the duration of a VCL task.
param.backend_idle_timeout
Type: DURATION
Readable from: all
Global parameter backend_idle_timeout.
param.backend_wait_limit
Type: INT
Readable from: all
Global parameter backend_wait_limit.
param.backend_wait_timeout
Type: DURATION
Readable from: all
Global parameter backend_wait_timeout.
param.between_bytes_timeout
Type: DURATION
Readable from: all
Global parameter between_bytes_timeout.
param.connect_timeout
Type: DURATION
Readable from: all
Global parameter connect_timeout.
param.default_grace
Type: DURATION
Readable from: all
Global parameter default_grace.
param.default_keep
Type: DURATION
Readable from: all
Global parameter default_keep.
param.default_ttl
Type: DURATION
Readable from: all
Global parameter default_ttl.
param.first_byte_timeout
Type: DURATION
Readable from: all
Global parameter first_byte_timeout.
param.idle_send_timeout
Type: DURATION
Readable from: all
Global parameter idle_send_timeout.
param.max_esi_depth
Type: INT
Readable from: all
Global parameter max_esi_depth.
param.max_restarts
Type: INT
Readable from: all
Global parameter max_restarts.
param.max_retries
Type: INT
Readable from: all
Global parameter max_retries.
param.pipe_task_deadline
Type: DURATION
Readable from: all
Global parameter pipe_task_deadline.
param.pipe_timeout
Type: DURATION
Readable from: all
Global parameter pipe_timeout.
param.send_timeout
Type: DURATION
Readable from: all
Global parameter send_timeout.
param.shortlived
Type: DURATION
Readable from: all
Global parameter shortlived.
param.timeout_idle
Type: DURATION
Readable from: all
Global parameter timeout_idle.
param.transit_buffer
Type: BYTES
Readable from: all
Global parameter transit_buffer.
param.uncacheable_ttl
Type: DURATION
Readable from: all
Global parameter uncacheable_ttl.
Protected header fields#
The content-length and transfer-encoding headers are read-only. They must be preserved to ensure HTTP/1 framing remains consistent and maintain a proper request and response synchronization with both clients and backends.
VMODs can still update these headers, when there is a reason to change the framing, such as a transformation of a request or response body.
HTTP response status#
A HTTP status code has 3 digits XYZ where X must be between 1 and 5 included. Since it is not uncommon to see HTTP clients or servers relying on non-standard or even invalid status codes, Varnish can work with any status between 100 and 999.
Within VCL code it is even possible to use status codes in the form VWXYZ as long as the overall value is lower than 65536, but only the XYZ part will be sent to the client, by which time the X must also have become non-zero.
The VWXYZ form of status codes can be communicate extra information in resp.status and beresp.status to return(synth(...)) and return(error(...)), to indicate which synthetic content to produce:
sub vcl_recv {
if ([...]) {
return synth(12404);
}
}
sub vcl_synth {
if (resp.status == 12404) {
[...] // this specific 404
} else if (resp.status % 1000 == 404) {
[...] // all other 404's
}
}
The obj.status variable will inherit the VWXYZ form, but in a ban expression only the XYZ part will be available. The VWXYZ form is strictly limited to VCL execution.
Assigning an HTTP standardized code to resp.status or beresp.status will also set resp.reason or beresp.reason to the corresponding status message.
304 handling#
For a 304 response, Varnish core code amends beresp before calling vcl_backend_response:
- If the gzip status changed,
Content-Encodingis unset and anyEtagis weakened - Any headers not present in the 304 response are copied from the existing cache object.
Content-Lengthis copied if present in the existing cache object and discarded otherwise. - The status gets set to 200.
beresp.was_304 marks that this conditional response processing has happened.
Note: Backend conditional requests are independent of client conditional requests, so clients may receive 304 responses no matter if a backend request was conditional.
beresp.ttl / beresp.grace / beresp.keep#
Before calling vcl_backend_response, core code sets beresp.ttl based on the response status and the response headers Age, Cache-Control or Expires and Date as follows:
- If present and valid, the value of the
Ageheader is effectively deduced from all ttl calculations. - For status codes 200, 203, 204, 300, 301, 304, 404, 410 and 414:
- If
Cache-Controlcontains ans-maxageormax-agefield (in that order of preference), the ttl is set to the respective non-negative value or 0 if negative. - Otherwise, if no
Expiresheader exists, the default ttl is used. - Otherwise, if
Expirescontains a time stamp beforeDate, the ttl is set to 0. - Otherwise, if no
Dateheader is present or theDateheader timestamp differs from the local clock by no more than the clock_skew parameter, the ttl is set to - 0 if
Expiresdenotes a past timestamp or - the difference between the local clock and the
Expiresheader otherwise. - Otherwise, the ttl is set to the difference between
ExpiresandDate
- If
- For status codes 302 and 307, the calculation is identical except that the default ttl is not used and -1 is returned if neither
Cache-ControlnorExpiresexists. - For all other status codes, ttl -1 is returned.
beresp.grace defaults to the default_grace parameter.
For a non-negative ttl, if Cache-Control contains a stale-while-revalidate field value, beresp.grace is set to that value if non-negative or 0 otherwise.
beresp.keep defaults to the default_keep parameter.
SEE ALSO#
HISTORY#
VCL was developed by Poul-Henning Kamp in cooperation with Verdens Gang AS, Redpill Linpro and Varnish Software. This manual page is written by Per Buer, Poul-Henning Kamp, Martin Blix Grydeland, Kristian Lyngstøl, Lasse Karstensen and others.
COPYRIGHT#
This document is licensed under the same license as Varnish itself. See LICENSE for details.
- Copyright (c) 2006 Verdens Gang AS
- Copyright (c) 2006-2021 Varnish Software AS
