Repository navigation
Support redirect: "error" behind a Fetch compatibility flag - #8973
Conversation
Let callers reject redirects without contacting the redirect target. With fetch_redirect_error enabled, fetch rejects with TypeError on any redirect status, even if the response has no Location header. Without the flag, Request continues to reject the mode during construction.
There was a problem hiding this comment.
Superseded by the review of
44ac2826.
This review, of 486c647b
💬 Approved with comments — The flag gating, redirect handling, serialization and tests are correct. The only note is an optional SUGGESTION: "error" is matched case-sensitively, unlike the other two redirect values.
Findings: 1 suggestion (1 is an inline comment on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 1 suggestion
The change is coherent and well tested. One optional note: "error" is matched case-sensitively, unlike "follow" and "manual".
Recommendation: 💬 Optional Nits
- [SUGGESTION]
redirect: "error"is matched case-sensitively, whilefollow/manualare matched case-insensitively throughtryParseRedirect. (src/workerd/api/http.c++:45)
View full review
parseRedirect falls back to tryParseRedirect, which uses strcasecmp, so "FOLLOW" and "Manual" are accepted. The new value == "error"_kj check is exact, so "ERROR" is rejected, and the test asserts that it is. Matching case-sensitively follows the Fetch spec, but the three valid values now behave differently. A short comment would show this is deliberate.
The redirect switch, the getRedirect() string, the serialization default and the compatibility flag definition are all correct.
✅ All other checks passed
🔒 Security: ✅ LGTM
No security issues found. In error mode the redirect target is never contacted, and a worker with the flag disabled rejects the mode when it deserializes the request.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md updates needed.
⚡ Performance: ✅ LGTM
No performance issues found.
📝 Documentation: ✅ LGTM
No documentation issues found. The pull request links its documentation change, which this repository's rules require before the flag's enable date.
Reviewed commit: 486c647b
Preserve the original validation error when the mode is disabled and test that requests received over RPC honor the receiving Worker’s flag.
486c647 to
44ac282
Compare
There was a problem hiding this comment.
Superseded by the review of
bb5bbf47.
This review, of 44ac2826
💬 Approved with comments — The flag gating, redirect handling, serialization and tests are correct. The one remaining note is an optional SUGGESTION: "error" is matched case-sensitively, unlike the other two redirect values.
Findings: 1 suggestion
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 1 suggestion
The flag gating, redirect handling, serialization and tests are correct. One optional suggestion is still open.
Recommendation: 💬 Optional Nits
- [SUGGESTION]
redirect: "error"is matched case-sensitively, whilefollow/manualare matched case-insensitively throughtryParseRedirect. (src/workerd/api/http.c++:45)
View full review
parseRedirect falls back to tryParseRedirect, which matches case-insensitively, so "FOLLOW" and "Manual" are accepted. The new value == "error"_kj check is exact, so "ERROR" is rejected, and the test asserts that it is. Exact matching follows the Fetch spec, but the three valid values now behave differently. A short comment would show that this is deliberate.
All uses of Redirect handle ERROR: the getRedirect() switch, serialization (the field is omitted only for FOLLOW, which matches the constructor default), deserialization and handleHttpResponse.
✅ All other checks passed
🔒 Security: ✅ LGTM
No security issues found. In error mode, fetch rejects any redirect status before it contacts the destination. A Worker with the flag disabled rejects the mode when it deserializes the request it receives over RPC.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md updates needed.
⚡ Performance: ✅ LGTM
No performance issues found.
📝 Documentation: ✅ LGTM
No documentation issues found. The pull request links its documentation change, which this repository requires before a flag's enable date.
Reviewed commit: 44ac2826
There was a problem hiding this comment.
Superseded by the review of
22cb754c.
This review, of bb5bbf47
✅ Approved — No open findings. The one earlier suggestion, about case-sensitive matching of "error", is now explained by a code comment, and the flag gating, redirect handling, serialization and tests are correct.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
In error mode, fetch rejects any redirect status before it reads Location or contacts the destination. When the flag is disabled, the mode is rejected at Request construction, including when the request arrives over RPC.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md updates needed.
📋 Code Quality: ✅ LGTM
Every use of Request::Redirect handles the new ERROR value:
getRedirect()- serialization, which omits the field only for
FOLLOW, the default when the request is read back - deserialization through
parseRedirect - clone
handleHttpResponse
The earlier note about case-sensitive matching is resolved by the explanatory comment at src/workerd/api/http.c++:45.
⚡ Performance: ✅ LGTM
No performance issues found.
📝 Documentation: ✅ LGTM
No documentation issues found. The pull request links the documentation for the new compatibility flag ahead of its enable date.
Reviewed commit: bb5bbf47
When the flag is off, tell callers how to opt in rather than saying that error mode will never be implemented. Keep rejecting the mode with a TypeError until the flag is enabled.
There was a problem hiding this comment.
✅ Approved — No findings. Since the last review, only the disabled-mode error message changed, the code still rejects the mode correctly when the flag is off, and the tests match the new message.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security issues found.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md updates needed.
📋 Code Quality: ✅ LGTM
No issues. The disabled-mode TypeError at src/workerd/api/http.c++:50-52 now points callers to fetch_redirect_error, and the test expectation matches it. ERROR is handled everywhere Request::Redirect is used. Serialization stays compatible with older versions because only FOLLOW, the default, is left out.
⚡ Performance: ✅ LGTM
No performance issues found.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: 22cb754c
Fixes #8971. Documentation: cloudflare/cloudflare-docs#35726.
fetch(url, { redirect: "error" })rejects a redirect without sending a request to its destination. Fetch rejects with aTypeErroron 301, 302, 303, 307, and 308, even when the response has noLocationheader. Other status codes are returned normally.Enabled by default for compatibility dates on or after
2026-12-22. Earlier dates can opt in withfetch_redirect_error; later dates can opt out withno_fetch_redirect_error. When disabled,Requestrejects the mode at construction with a TypeError that tells callers how to enablefetch_redirect_error.Tests cover flag-enabled and legacy behavior, redirect handling with and without
Location, destination request counts, cloning, serialization, and a request returned over RPC to a Worker with the flag disabled. The generic compatibility-date suite, both redirect test variants, and both Fetch API web-platform test variants passed after removing the flag-specific date test.