Skip to content

Follow only 301, 302, 303, 307 and 308 redirects - #2646

Merged
yhirose merged 2 commits into
yhirose:masterfrom
wleeaf:follow-only-redirect-statuses
Oct 25, 2026
Merged

yhirose merged 2 commits into
yhirose:masterfrom
wleeaf:follow-only-redirect-statuses

Conversation

@wleeaf

@wleeaf wleeaf commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

detail::is_redirect treats any status from 301 to 399 that has a Location as a redirect. With set_follow_location(true), a 304 Not Modified, a 305 Use Proxy or a 306 that carries a Location header makes the client request that location and return its response instead. The comment above the function already says a 304 is a final response. A 304 has no new target, and 305 was deprecated "due to security concerns regarding in-band configuration of a proxy" (RFC 7231, Appendix B).

The redirections RFC 9110 defines for a client to follow are 301, 302, 303, 307 and 308 (section 15.4). The Fetch standard's redirect statuses are the same set, and detail::redirect only special-cases 303. is_redirect now accepts only these five statuses, and a Location is still required. 300 Multiple Choices wasn't followed before and still isn't.

The new RedirectTest.OtherStatusesWithLocationAreNotFollowed serves a 304 and a 305 with Location: /target and expects the client to return them without requesting /target. Without the change, both are followed and return 200. The redirect tests and the new test pass with the change (OpenSSL build, with g++), and git clang-format reports nothing for the change.

wleeaf and others added 2 commits October 25, 2026 16:14
With follow_location, any 3xx from 301 to 399 that had a Location was
followed, so a 304 Not Modified, a 305 Use Proxy or a 306 with a
Location header made the client request that location and return its
response instead. Only 301, 302, 303, 307 and 308 are redirections the
client can follow (RFC 9110, section 15.4; the Fetch standard uses the
same set); any other 3xx is now returned as the final response.
@yhirose
yhirose merged commit 7d349cb into yhirose:master Oct 25, 2026
26 of 28 checks passed
@yhirose

yhirose commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants