Forwarded
The Forwarded header provides metadata about the message from intermediate nodes (proxies and gateways), that would otherwise be lost. For example, the IP address of the connected client. This header is similar to the Via header, except it is never required, it is only used in requests, and it can provide more infomation.
It is typically implemented in gateways that want to preserve the IP address of the connecting client.
The header lists one or more nodes, listed upstream to downstream (comma-delimited), each containing one or more parameters (semicolon-delimited, no whitespace):
- by
- The address of the node itself.
- for
- Identifies the source address of the client making the request to the node.
- host
- The
Host
request header field as received by the node. This should be used by gateways that change the Host header. - proto
- Indicates what protocol was used to make the request. This should be used if the node forwards the request with a different protocol.
Writing requests (clients)
User-agents do not send this header as they are the originator of the message.
Intermediate nodes (caches, proxies, and gateways) should add themselves to the list. Gateways should ensure the header is in a format with the information desired by the downstream origin server, so that the origin server will read the user-agent IP address correctly.
Reading requests (servers)
This is an informational header. If the server is behind a gateway, it can read the last item's "for" parameter to retreive the requesting client IP, instead of reading the TCP IP address (which will be the gateway's IP address, instead of the end user).
Older versions
The Forwarded header is a standardized version of similar headers commonly seen in gateways, such as X-Forwarded-For
. Nodes that understand such headers are encouraged to translate these fields into a Forwarded header, see RFC7239 ยง7.4. Transition for advice.
Overview table
- Name
- Forwarded
- Description
- Provides connection metadata from upstream nodes.
- Direction
- Request
- Specification
- RFC7239: Forwarded HTTP Extension
Syntax
Forwarded = 1#forwarded-element
forwarded-element = [ forwarded-pair ] *( ";" [ forwarded-pair ] )
forwarded-pair = token "=" value
value = token / quoted-string
Examples
Forwarded: for="_gazonk"
Forwarded: For="[2001:db8:cafe::17]:4711"
Forwarded: for=192.0.2.60;proto=http;by=203.0.113.43
Forwarded: for=192.0.2.43, for=198.51.100.17