Header reference
Fastly cache servers read and write HTTP headers as part of the process of caching and routing requests and responses. This section defines all the headers that are meaningful to Fastly and how they affect the way a Fastly service will behave.
Edge Platform
- Accept-Encoding
- Age
- Alt-Svc
- CDN-Loop
- Cache-Control
- Content-Length
- Content-Range
- Cookie
- Date
- Expect
- Expires
- Fastly-Cachetype
- Fastly-Client
- Fastly-Client-IP
- Fastly-Cookie-Overflow
- Fastly-Debug
- Fastly-Debug-Digest
- Fastly-Debug-Path
- Fastly-Debug-TTL
- Fastly-FF
- Fastly-Force-Shield
- Fastly-No-Shield
- Fastly-SSL
- Host
- Proxy-Authenticate
- Proxy-Authorization
- Surrogate-Control
- Surrogate-Key
- TE
- Trailer
- Transfer-Encoding
- Upgrade
- Vary
- X-Cache
- X-Cache-Hits
- X-Compress-Hint
- X-Forwarded-For
- X-Forwarded-Host
- X-Forwarded-Server
- X-Served-By
- X-Timer
- X-Varnish
API
Media Products
- Fastly-IO-Error
- Fastly-IO-Info
- Fastly-IO-Warning
- Fastly-Stats
- X-Fastly-Imageopto-API
- X-Fastly-Imageopto-Montage
- X-Fastly-Imageopto-Overlay
Reading and setting HTTP headers
In VCL, it's possible to read and write HTTP headers on the incoming client request (req.http.{NAME}
), the request to the backend (bereq.http.{NAME}
), the response from the backend (beresp.http.{NAME}
), or the response to the client (resp.http.{NAME}
). It's also possible to read and write headers on a cache object (obj.http.{NAME}
) in some parts of the VCL flow.
To set the value of a header, use the set
or add
statements:
set req.http.Custom-Header = "some=1, data=2, here=3";set req.http.Another-Header = "header-values-can-be-any-string-data";
While you can set the value of a header in any format you like, using structured fields is a good way to make the values easier to parse later. In fact, if you use this format, you can access subfields using a convenience syntax in VCL:
set req.http.Cache-Control:max-age = "3600";
This subfield accessor syntax also works for reading headers:
if (req.http.cookie:cookie-name) { # Do something with the 'cookie-name' cookie}
Some headers, such as Vary
, take a list of keys (in the case of Vary
, a list of other header names), but no values. Subfield syntax can be used to add or remove keys from these kinds of headers:
set resp.http.Vary:Accept-Encoding = ""; // Add "Accept-Encoding" to the Vary headerunset resp.http.Vary:User-Agent; // Remove "User-Agent" from the Vary header