Variables in VCL
VCL provides many predefined variables that describe the state and properties of a request, as well as a mechanism for declaring local variables.
Local variables are scoped to the subroutine or block in which they are defined. Predefined variables have different scopes depending on their purpose and content, with availability indicated on each variable's reference page.
Predefined variables
Explore all available variables here:
- Backend connection
- Backend request
- Backend response
- Cache object
- Client connection
- Client request
- Client response
- Date and time
- ESI
- Geolocation
- Math constants limits
- Miscellaneous
- Rate limiting
- Segmented caching
- Server
Several predefined variables relate to various views of the HTTP exchange:
the client request (req), backend request (bereq), backend response (beresp), cached object (obj), and client response (resp).
These are accessible in their respective parts of the VCL lifecycle (for [R]eading and [W]riting):
| Variable | recv | hash | hit | miss | pass | fetch | error | deliver | log |
|---|---|---|---|---|---|---|---|---|---|
| req.* | R/W | R/W | R/W | R/W | R/W | R/W | R/W | R/W | R/W |
| bereq.* | R/W | R/W | R/W | R 1️⃣ | |||||
| obj.* | R | R/W | |||||||
| beresp.* | R/W | ||||||||
| resp.* | R/W | R/W |
1️⃣ A small number of bereq. variables are available to read in the vcl_log subroutine.
User defined local variables
See Local variables for information on declaring and using user defined variables.