<!-- review: finished -->

<a id="http-headers"></a>

# Headers

Allows adding the `Expires` and `Cache-Control` header fields, and arbitrary fields, to a response header.

<a id="configuration-example-22"></a>

## Configuration Example

```nginx
expires    24h;
expires    modified +24h;
expires    @24h;
expires    0;
expires    -1;
expires    epoch;
expires    $expires;
add_header Cache-Control private;
```

<a id="directives-23"></a>

## Directives

<a id="index-0"></a>

<a id="add-header"></a>

### add_header

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `add_header` name value [`always`];    |
|------------------------------------------------------------------------------------------|----------------------------------------|
| Default                                                                                  | —                                      |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, if in location |

Adds the specified field to a response header provided that the response code equals 200, 201 (1.3.10), 204, 206, 301, 302, 303, 304, 307, or 308. Parameter value can contain variables.

There could be several `add_header` directives. These directives are inherited from the previous configuration level if and only if there are no `add_header` directives defined on the current level.

If the `always` parameter is specified, the header field will be added regardless of the response code.

<a id="index-1"></a>

<a id="add-trailer"></a>

### add_trailer

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `add_trailer` name value [`always`];   |
|------------------------------------------------------------------------------------------|----------------------------------------|
| Default                                                                                  | —                                      |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, if in location |

Adds the specified field to the end of a response provided that the response code equals 200, 201, 206, 301, 302, 303, 307, or 308. Parameter value can contain variables.

There could be several `add_trailer` directives. These directives are inherited from the previous configuration level if and only if there are no `add_trailer` directives defined on the current level.

If the `always` parameter is specified, the specified field will be added regardless of the response code.

<a id="index-2"></a>

<a id="expires"></a>

### expires

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `expires` [`modified`] time;<br/><br/>`expires` `epoch` | `max` | `off`;   |
|------------------------------------------------------------------------------------------|----------------------------------------------------------------------------|
| Default                                                                                  | `expires off;`                                                             |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, if in location                                     |

Enables or disables adding or modifying the `Expires` and `Cache-Control` response header fields provided that the response code equals 200, 201, 204, 206, 301, 302, 303, 304, 307, or 308. The parameter can be a positive or negative [time](https://en.angie.software//angie/docs/configuration/configfile.md#syntax).

The time in the `Expires` field is computed as a sum of the current time and time specified in the directive. If the `modified` parameter is used, then the time is computed as a sum of the file's modification time and the time specified in the directive.

In addition, it is possible to specify a time of day using the "@" prefix:

```nginx
expires @15h30m;
```

The contents of the `Cache-Control` field depends on the sign of the specified time:

* time is negative — "Cache-Control: no-cache".
* time is positive or zero — "Cache-Control: max-age=\`t\`", where t is a time specified in the directive, in seconds.

| `epoch`   | sets `Expires` to the value "Thu, 01 Jan 1970 00:00:01 GMT", and `Cache-Control` to "no-cache".   |
|-----------|---------------------------------------------------------------------------------------------------|
| `max`     | sets `Expires` to the value "Thu, 31 Dec 2037 23:55:55 GMT", and `Cache-Control` to 10 years.     |
| `off`     | disables adding or modifying the `Expires` and `Cache-Control` response header fields.            |

The last parameter value can contain variables:

```nginx
map $sent_http_content_type $expires {
    default         off;
    application/pdf 42d;
    ~image/         max;
}

expires $expires;
```
