set

Available inall 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:

OperatorPurpose
=Simple assignment
+=Addition
-=Subtraction
*=Multiplication
/=Division
%=Remainder
|=Bitwise OR
&=Bitwise AND
^=Bitwise XOR
<<=Left shift
>>=Right shift

Try it out

set is used in the following code examples. Examples apply VCL to real-world use cases and can be deployed as they are, or adapted for your own service. See the full list of code examples for 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.