Skip to content

Support redirect: "error" behind a Fetch compatibility flag - #8973

Merged
danlapid merged 4 commits into
mainfrom
dlapid/fetch-redirect-error
Nov 29, 2026
Merged

danlapid merged 4 commits into
mainfrom
dlapid/fetch-redirect-error

Conversation

@danlapid

@danlapid danlapid commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #8971. Documentation: cloudflare/cloudflare-docs#35726.

fetch(url, { redirect: "error" }) rejects a redirect without sending a request to its destination. Fetch rejects with a TypeError on 301, 302, 303, 307, and 308, even when the response has no Location header. Other status codes are returned normally.

Enabled by default for compatibility dates on or after 2026-12-22. Earlier dates can opt in with fetch_redirect_error; later dates can opt out with no_fetch_redirect_error. When disabled, Request rejects the mode at construction with a TypeError that tells callers how to enable fetch_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.

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.
@danlapid
danlapid marked this pull request as ready for review November 28, 2026 20:45
@danlapid
danlapid requested review from a team as code owners November 28, 2026 20:45

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, while follow/manual are matched case-insensitively through tryParseRedirect. (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

Comment thread src/workerd/api/http.c++ Resolved
Preserve the original validation error when the mode is disabled and
test that requests received over RPC honor the receiving Worker’s flag.
@danlapid
danlapid force-pushed the dlapid/fetch-redirect-error branch from 486c647 to 44ac282 Compare November 28, 2026 20:56

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, while follow/manual are matched case-insensitively through tryParseRedirect. (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

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/wpt/BUILD.bazel Resolved
Comment thread src/workerd/api/http.c++ Resolved
Comment thread src/workerd/api/http.c++ Resolved
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.

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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

@danlapid
danlapid merged commit 82592e0 into main Nov 29, 2026
24 of 26 checks passed
@danlapid
danlapid deleted the dlapid/fetch-redirect-error branch November 29, 2026 22:41
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.

✨ Feature Request — implement the Fetch standard redirect: "error" mode

2 participants