Skip to content

feat(node): add per-request redirect option to RequestInit#418

Open
privatenumber wants to merge 2 commits intoapify:masterfrom
privatenumber:feat/per-request-redirect
Open

feat(node): add per-request redirect option to RequestInit#418
privatenumber wants to merge 2 commits intoapify:masterfrom
privatenumber:feat/per-request-redirect

Conversation

@privatenumber
Copy link

Summary

Adds standard Fetch API redirect option to RequestInit, allowing per-request override of the instance-level followRedirects setting.

  • 'follow' — follow redirects (default, matches instance behavior)
  • 'manual' — return the 3xx response as-is
  • 'error' — throw TypeError on redirect

When set, overrides the instance-level followRedirects for that request. When omitted, instance-level followRedirects / maxRedirects are used as before.

Also extracts Request.redirect when a Request object is passed — but only for non-default values ('manual', 'error'), since Request.redirect defaults to 'follow' per the Fetch API spec and would otherwise silently override instance-level followRedirects: false.

Changes

  • index.wrapper.js — extract redirect in parseFetchOptions, thread through fetch()#fetchWithRedirectHandling(), override instance-level followRedirects / throw on 'error'
  • dts-header.d.ts — add redirect to RequestInit via interface merging
  • test/basics.test.ts — replace skipped httpbin-based redirect tests with 15 local server tests covering all modes, overrides, Request objects, status codes
  • test/mock.server.ts — add /redirect/:n, /redirect-to, /get routes
  • README.md — add per-request redirect usage example

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.
@privatenumber privatenumber marked this pull request as ready for review March 22, 2026 07:30
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