Skip to content

Forwarded

Description

The Forwarded request header is used to provide information about the original client making a request through an HTTP proxy or load balancer. It helps identify the client's original IP address, protocol, and other parameters that might otherwise be lost when passing through intermediaries.

The Forwarded header is designed to replace older headers such as X-Forwarded-For, X-Forwarded-Proto, and X-Forwarded-Host by providing a standardized way to track request origins.

Syntax

The syntax of the Forwarded header follows this structure:

Forwarded: by=<identifier>; for=<client>; host=<host>; proto=<protocol>
  • by=<identifier>: Specifies the proxy server handling the request.
  • for=<client>: Indicates the original client's IP address.
  • host=<host>: Represents the original host requested by the client.
  • proto=<protocol>: Specifies the protocol used by the client (e.g., http or https).

Example Syntax

Forwarded: for=192.168.1.1; proto=https
Forwarded: by=proxy1.example.com; for=192.168.1.100; host=example.com; proto=http

Examples

Tracking the Original Client IP

If a client at 192.168.1.1 makes a request through a proxy, the proxy adds the Forwarded header:

GET / HTTP/1.1
Host: example.com
Forwarded: for=192.168.1.1

The server can use this information to determine the actual source of the request.

Indicating the Protocol Used by the Client

A request originally made using HTTPS but forwarded through a proxy can include:

GET /secure-data HTTP/1.1
Host: example.com
Forwarded: for=203.0.113.5; proto=https

This helps the server identify whether the client originally used a secure connection.

Forwarding Multiple Proxies

If a request passes through multiple proxies, each proxy appends its information:

Forwarded: for=192.168.1.1, for=203.0.113.2

Summary

The Forwarded request header provides a standardized way to communicate information about the original request when passing through proxies or load balancers. It helps servers determine the client's original IP address, protocol, and host details, improving logging, security, and request handling. Proper use of this header enhances transparency and traceability in distributed networks.