Available in all subroutines.

Sets the value of a variable or HTTP header.

set var.custom_string_variable = "foo";
set obj.status = 307;
set obj.http.Location = "/login";

set will overwrite the value of an existing header (to append instead, see add). To set a single token in a comma-separated list of key-value pairs in the header value, set also supports subfield accessors:

set resp.http.Cache-Control:max-age = "300";
set resp.http.Vary:Accept-Encoding = ""; # empty string adds "Accept-Encoding" to the header value as a standalone token

The set statement allows for a variety of operators:

=Simple assignment
|=Bitwise OR
&=Bitwise AND
^=Bitwise XOR
<<=Left shift
>>=Right shift

Try it out

set is used in the following solution recipes. Recipes apply VCL to real-world use cases and can be deployed as-is, or adapted for your own service. See the full list of recipesfor more inspiration.

Click RUN on a sample below to provision a Fastly service, execute the code on Fastly, and see how the function behaves.

Add, remove or change HTTP headers

Fastly can easily read and write HTTP headers at multiple stages of the request/response cycle.

Math assignment operators

Use addition, subtraction, multiplication, division, and modulus operators when assigning numeric values to headers or variables.

User contributed notes

We welcome comments that add use cases, ideas, tips, and caveats. All comments will be moderated before publication. To post support questions, visit our support center and we'll find you the help you need.