---
title: header.set
summary: null
url: >-
  https://www.fastly.com/documentation/reference/vcl/functions/headers/header-set
---

```
VOID header.set(ID where, STRING header_name, STRING value)
```

**Available in:** all subroutines

Sets a header by name.
This is equivalent to the `set` statement except that the header name
is given as a string, and may be passed dynamically.
Header names are case insensitive.

The _where_ argument is one of the literal identifiers `req`, `resp`, `obj`,
`bereq`, or `beresp`, corresponding to the [predefined
variable](https://www.fastly.com/documentation/reference/vcl/variables/) of the same
name. The predefined variable associated with the _where_ argument must be
writable within the VCL subroutine where `header.set()` is called.

```vcl
header.set(req, "abc", "xyz");
```

is equivalent to:

```vcl
set req.http.abc = "xyz";
```

See also the [set statement](https://www.fastly.com/documentation/reference/vcl/statements/set/),
the [client request](https://www.fastly.com/documentation/reference/vcl/variables/client-request/req-http/),
and other [request and response](https://www.fastly.com/documentation/reference/vcl/variables/) variables.

Some headers are _protected_. These headers cannot be set,
and the `header.set()` function has no effect.
See the [Header reference](https://www.fastly.com/documentation/reference/http/http-headers/)
for which headers are protected.

Calling `header.set()` for a header which does not exist, or passing the empty string,
a _not-set_ value, or a string that would be invalid as a header name,
also has no effect.

## Header names

A valid header name consists of one or more of the following characters:

```
! # $ % & ' * + - . 0-9 A-Z ^ _ ` a-z | ~
```

This is beyond what's possible to set by the `set resp.http.xyz = ...;` syntax because
some of these characters are not permitted in VCL variable names.
For example, it is possible to set a header named `hello!` (with the exclamation mark):

```
header.set(resp, "hello!", "abc"); # in the http response: hello!: abc
```

which is not possible using the `set resp.http.xyz = ...;` syntax.

Leading and trailing whitespace are not permitted in header names.

The maximum length for a header name is 126 characters.
