feat(node): add per-request redirect option to RequestInit#418
Open
privatenumber wants to merge 2 commits intoapify:masterfrom
Open
feat(node): add per-request redirect option to RequestInit#418privatenumber wants to merge 2 commits intoapify:masterfrom
redirect option to RequestInit#418privatenumber wants to merge 2 commits intoapify:masterfrom
Conversation
Support standard Fetch API `redirect` option ('follow' | 'manual' | 'error')
on individual requests, overriding the instance-level `followRedirects` setting.
…ollowRedirects Request.redirect defaults to 'follow' per Fetch API spec, making it impossible to distinguish from an explicit 'follow'. Only extract non-default redirect values from Request objects to avoid silently overriding instance-level followRedirects: false. Also adds tests for: error mode on non-redirect response, follow with maxRedirects, init overriding Request.redirect, 301/307 codes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds standard Fetch API
redirectoption toRequestInit, allowing per-request override of the instance-levelfollowRedirectssetting.'follow'— follow redirects (default, matches instance behavior)'manual'— return the 3xx response as-is'error'— throwTypeErroron redirectWhen set, overrides the instance-level
followRedirectsfor that request. When omitted, instance-levelfollowRedirects/maxRedirectsare used as before.Also extracts
Request.redirectwhen aRequestobject is passed — but only for non-default values ('manual','error'), sinceRequest.redirectdefaults to'follow'per the Fetch API spec and would otherwise silently override instance-levelfollowRedirects: false.Changes
index.wrapper.js— extractredirectinparseFetchOptions, thread throughfetch()→#fetchWithRedirectHandling(), override instance-levelfollowRedirects/ throw on'error'dts-header.d.ts— addredirecttoRequestInitvia interface mergingtest/basics.test.ts— replace skipped httpbin-based redirect tests with 15 local server tests covering all modes, overrides, Request objects, status codestest/mock.server.ts— add/redirect/:n,/redirect-to,/getroutesREADME.md— add per-request redirect usage example