CDN-Loop
The HTTP CDN-Loop request header enables Content Delivery Networks to detect and prevent request forwarding loops by appending identifiers as requests traverse each CDN in the chain.
Usage
When multiple CDNs forward requests between each other, a misconfiguration or routing error creates the risk of a non-terminating loop. A request enters CDN A, gets forwarded to CDN B, and then accidentally routes back to CDN A. Without detection, the request cycles indefinitely until timeout.
The CDN-Loop header solves this by requiring each CDN to append its identifier to the header before forwarding. Before processing a request, each CDN checks the header for its own identifier. If found, the CDN has already processed the request and a loop exists. The CDN terminates the request immediately instead of forwarding again.
The header uses a comma-separated list of CDN identifiers, each optionally followed by semicolon-separated parameters. Cloudflare, Fastly, and other major CDN providers implement this mechanism.
Each cdn-id is either a pseudonym chosen by the CDN or a hostname the CDN controls. Pseudonyms need enough entropy to avoid accidental collisions between different CDN providers. Common practice uses the recognized CDN name or a UUID.
Directives
cdn-id
The CDN identifier. Each CDN appends its own identifier when forwarding a request. The identifier is a token representing the CDN processing the request. Multiple CDN identifiers appear comma-separated in the order requests passed through each hop.
loops
An integer parameter indicating how many times the CDN has seen the request. The value increments each time the same CDN processes the same request. A value greater than 1 indicates a loop. This parameter is a Cloudflare-specific extension, not part of the standard.
subreqs
An integer parameter tracking subrequest count. Used by CDNs generating additional internal requests while processing the original request. This parameter is also a Cloudflare-specific extension, not part of the standard.
Example
A request traverses Cloudflare once with no subrequests. The loops=1
parameter shows this is the first time Cloudflare has processed the
request. Note: loops and subreqs are Cloudflare-specific
extensions. The specification allows optional
parameters but does not define any.
CDN-Loop: cloudflare; loops=1
A request triggering internal subrequests within Cloudflare. The
subreqs=1 parameter indicates Cloudflare generated one additional
internal request while processing.
CDN-Loop: cloudflare; loops=1; subreqs=1
A request passing through multiple CDNs. Each CDN appends its identifier. The comma-separated list shows the forwarding path.
CDN-Loop: cdn-a; loops=1, cdn-b; loops=1, cdn-c; loops=1
A detected loop where Cloudflare has processed the same request twice.
The loops=2 value triggers loop detection and request termination.
CDN-Loop: cloudflare; loops=2
Takeaway
The CDN-Loop header prevents infinite request forwarding loops between CDNs by requiring each CDN to append its identifier and check for its own presence before forwarding.