Summary
The headers module allows for the customization of HTTP request and response headers. The module allows headers to be merged, replaced or removed.
Directives
Module: mod_headers | |
Syntax: Header [condition] set|append|add header value [env=[!]variable] | |
Default: none | |
Context: server config, virtual host, directory, .htaccess | |
Override: FileInfo | |
Origin: Apache | |
Example: Header append Author "John P. Doe" | |
Example: Header unset Author | |
Example: Header echo ^TS* | |
Example: Header echo Host |
The Header directive can replace, merge or remove HTTP response headers. The action performed by this module is determined by the action parameter. This parameter is followed by a header name, which can include the final colon, but it is not required. Case is also ignored. For add, append, and set, a value is given as the next parameter. If this value contains spaces, it should be surrounded by double quotes. For "unset", no value should be given.
Note:The [condition] parameter was introduced with Apache 2.0.52. It did not exist prior to this version on iSeries™.
Order of Processing
The Header directive can occur almost anywhere within the server configuration. It is valid in the main server config and virtual host contexts, inside <Directory>, <Location>, and <Files> contexts and within .htaccess files.
The Header directives are processed in the following order:
Order is important. These two headers have a different effect if reversed. For example:
Header append Author "John P. Doe" Header unset Author
This way the Author header is not set. If reversed, the Author header is set to "John P. Doe". The Header directives are processed just before the response is sent by its handler. This means that some headers, that are added just before the response is sent, cannot be changed or overridden. This includes headers such as Date and Server.
Condition | Description |
---|---|
onsuccess | The Header directive will only effect responses with a status code of 2xx. |
always | The Header directive will effect all responses, including 2xx. |
Action | Description |
---|---|
set | The response header is set, replacing any previous header with this name. |
append | The response header is appended to any existing header of the same name. When a new value is merged onto an existing header it is separated from the existing header with a comma. This is the HTTP standard way of giving a header multiple values. |
add | The response header is added to the existing set of headers, even if this header already exists. This can result in two (or more) headers having the same name. This can lead to unforeseen consequence, and in general, "append" should be used instead. |
unset | The response header of this name is removed, if it exists. If there are multiple headers of the same name, all will be removed. |
echo | Request headers with this name are echoed back in the response headers. Header may be a regular expression. Echo without any parameters echoes back all the request headers in the response. |
Other format strings, such as %s, will receive an error and the server will not start.
The Header directives are processed just before the response is sent to the network. This means that it is possible to set or override most headers, except for those headers added by the header filter.
Module: mod_headers | |
Syntax: RequestHeader action header value | |
Default: none | |
Context: server config, virtual host, directory, .htaccess | |
Override: none | |
Origin: Apache | |
Example: RequestHeader set Accept-Encoding "gzip | |
Example: RequestHeader unset Referer |
The RequestHeader directive can replace, merge or remove HTTP request headers. The header is modified just before the content handler is run, allowing incoming headers to be modified. The action it performs is determined by the first argument.
This argument is followed by a header name, which can include the final colon, but it is not required. Case is ignored. For add, append, and set, a value is given as the third argument. If this value contains spaces, it should be surrounded by double quotes. For unset, no value should be given.
Order of Processing
The RequestHeader (and Header) directives can occur almost anywhere within the server configuration. It is valid in the main server config and virtual host sections, inside <Directory>, <Location>, and <Files> sections, and whithin .htaccess files.
The RequestHeader directives are processed in the following order:
Order is important. These two headers have a different effect if reversed:
RequestHeader append MirrorID "mirror 12" RequestHeader unset MirrorID
This way round, the MirrorID header is not set. If reversed, the MirrorID header is set to "mirror 12".
The RequestHeader directive is processed just before the request is run by its handler in the fixup phase. This should allow headers generated by the browser, or by Apache input filters to be overridden or modified. For example,
RequestHeader append MirrorID "mirror 12"
Action | Description |
---|---|
set | The request header is set, replacing any previous header with this name. |
append | The request header is appended to any existing header of the same name. When a new value is merged into an existing header, it is separated from the existing header with a comma. This is the HTTP standard way of giving a header multiple values. |
add | The request header is added to the existing set of headers, even if this header already exists. This can result in two (or more) headers having the same name. This can lead to unforeseen consequences, and in general append should be used instead. |
unset | The request header of this name is removed, if it exists. If there are multiple headers of the same name, all will be removed. |