Max-Forwards
The HTTP Max-Forwards request header limits the number of times intermediaries forward an HTTP TRACE or OPTIONS request.
Usage
The Max-Forwards header provides a mechanism for tracing the path a request takes through proxies and gateways. Each intermediary in the chain decrements the value by one before forwarding the request. When the count reaches zero, the intermediary stops forwarding and responds directly.
This behavior is useful for diagnosing routing issues. Setting the value to zero targets the first proxy in the chain. Incrementing the value by one for each subsequent request maps out each intermediary along the path. The Via header in the response identifies which intermediary handled the request at each hop.
The header applies exclusively to TRACE and OPTIONS methods. Intermediaries receiving Max-Forwards on other request methods ignore the header and forward the request normally.
When an intermediary receives a Max-Forwards value of zero on a TRACE request, the intermediary responds with a 200 status and echoes the received request as the response body. For an OPTIONS request with a zero value, the intermediary responds with the communication options available at the intermediary itself.
Directives
integer-value
A non-negative integer indicating the maximum number of remaining hops. Each intermediary decrements the value before forwarding.
Max-Forwards: <integer>
Example
A diagnostic TRACE request targets the second intermediary in the chain by setting Max-Forwards to 2. The first proxy decrements the value to 1 and forwards the request. The second proxy decrements to 0 and responds directly.
TRACE / HTTP/1.1
Host: origin.example.re
Max-Forwards: 2
The first proxy forwards the request with a decremented value.
TRACE / HTTP/1.1
Host: origin.example.re
Max-Forwards: 1
Via: 1.1 proxy-a.example.re
The second proxy reaches zero, stops forwarding, and returns the request as the response body.
HTTP/1.1 200 OK
Content-Type: message/http
TRACE / HTTP/1.1
Host: origin.example.re
Max-Forwards: 0
Via: 1.1 proxy-a.example.re, 1.1 proxy-b.example.re
Takeaway
The Max-Forwards header caps how many intermediaries forward a TRACE or OPTIONS request. Each proxy decrements the counter, and the proxy reaching zero responds directly instead of forwarding.