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.

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 header
unset resp.http.Vary:User-Agent; // Remove "User-Agent" from the Vary header