Apache HTTP Server Version 2.2
Description: | Customization of HTTP request and response headers |
---|---|
Status: | Extension |
Module Identifier: | headers_module |
Source File: | mod_headers.c |
This module provides directives to control and modify HTTP request and response headers. Headers can be merged, replaced or removed.
The directives provided by mod_headers
can
occur almost anywhere within the server configuration, and can be
limited in scope by enclosing them in configuration sections.
Order of processing is important and is affected both by the order in the configuration file and by placement in configuration sections. These two directives 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".
mod_headers
can be applied either early or late
in the request. The normal mode is late, when Request Headers are
set immediately before running the content generator and Response
Headers just as the response is sent down the wire. Always use
Late mode in an operational server.
Early mode is designed as a test/debugging aid for developers.
Directives defined using the early
keyword are set
right at the beginning of processing the request. This means
they can be used to simulate different requests and set up test
cases, but it also means that headers may be changed at any time
by other modules before generating a Response.
Because early directives are processed before the request path's
configuration is traversed, early headers can only be set in a
main server or virtual host context. Early directives cannot depend
on a request path, so they will fail in contexts such as
<Directory>
or <Location>
.
Header echo ^TS
MyHeader
, to the response including a
timestamp for when the request was received and how long it
took to begin serving the request. This header can be used by
the client to intuit load on the server or in isolating
bottlenecks between the client and the server.
Header set MyHeader "%D %t"
results in this header being added to the response:
MyHeader: D=3775428 t=991424704447256
Header set MyHeader "Hello Joe. It took %D microseconds \
for Apache to serve this request."
results in this header being added to the response:
MyHeader: Hello Joe. It took D=3775428 microseconds for Apache
to serve this request.
MyHeader
on the response if and
only if header MyRequestHeader
is present on the request.
This is useful for constructing headers in response to some client
stimulus. Note that this example requires the services of the
mod_setenvif
module.
SetEnvIf MyRequestHeader myvalue HAVE_MyRequestHeader
Header set MyHeader "%D %t mytext" env=HAVE_MyRequestHeader
If the header MyRequestHeader: myvalue
is present on
the HTTP request, the response will contain the following header:
MyHeader: D=3775428 t=991424704447256 mytext
RequestHeader edit Destination ^https: http: early
CGI
, NO_CACHE
and
NO_STORE
environment variables all existed for the
request):
Header merge Cache-Control no-cache env=CGI
Header merge Cache-Control no-cache env=NO_CACHE
Header merge Cache-Control no-store env=NO_STORE
then the response would contain the following header:
Cache-Control: no-cache, no-store
If append
was used instead of merge
,
then the response would contain the following header:
Cache-Control: no-cache, no-cache, no-store
Description: | Configure HTTP response headers |
---|---|
Syntax: | Header [condition] set|append|merge|add|unset|echo|edit
header [value] [replacement]
[early|env= |