@whatwg-node/node-fetch 0.7.8 → 0.7.9-alpha-20250213114401-de7d1130414fecb9eaf387c5024f8c53032fc246

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/fetchCurl.js CHANGED
@@ -118,7 +118,8 @@ function fetchCurl(fetchRequest) {
118
118
  .filter(headerFilter => {
119
119
  if (headerFilter && !headerFilter.startsWith('HTTP/')) {
120
120
  if (fetchRequest.redirect === 'error' &&
121
- (headerFilter.includes('location') || headerFilter.includes('Location'))) {
121
+ (headerFilter.includes('location') || headerFilter.includes('Location')) &&
122
+ (0, utils_js_1.shouldRedirect)(status)) {
122
123
  if (!stream.destroyed) {
123
124
  stream.resume();
124
125
  }
@@ -73,7 +73,7 @@ function fetchNodeHttp(fetchRequest) {
73
73
  default:
74
74
  outputStream = new node_stream_1.PassThrough();
75
75
  }
76
- if (nodeResponse.headers.location) {
76
+ if (nodeResponse.headers.location && (0, utils_js_1.shouldRedirect)(nodeResponse.statusCode)) {
77
77
  if (fetchRequest.redirect === 'error') {
78
78
  const redirectError = new Error('Redirects are not allowed');
79
79
  reject(redirectError);
package/cjs/utils.js CHANGED
@@ -7,6 +7,7 @@ exports.isArrayBufferView = isArrayBufferView;
7
7
  exports.isNodeReadable = isNodeReadable;
8
8
  exports.createDeferredPromise = createDeferredPromise;
9
9
  exports.isIterable = isIterable;
10
+ exports.shouldRedirect = shouldRedirect;
10
11
  function isHeadersInstance(obj) {
11
12
  return obj?.forEach != null;
12
13
  }
@@ -88,3 +89,6 @@ function createDeferredPromise() {
88
89
  function isIterable(value) {
89
90
  return value?.[Symbol.iterator] != null;
90
91
  }
92
+ function shouldRedirect(status) {
93
+ return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
94
+ }
package/esm/fetchCurl.js CHANGED
@@ -2,7 +2,7 @@ import { PassThrough, Readable } from 'node:stream';
2
2
  import { pipeline } from 'node:stream/promises';
3
3
  import { rootCertificates } from 'node:tls';
4
4
  import { PonyfillResponse } from './Response.js';
5
- import { createDeferredPromise, defaultHeadersSerializer, isNodeReadable } from './utils.js';
5
+ import { createDeferredPromise, defaultHeadersSerializer, isNodeReadable, shouldRedirect, } from './utils.js';
6
6
  export function fetchCurl(fetchRequest) {
7
7
  const { Curl, CurlFeature, CurlPause, CurlProgressFunc } = globalThis['libcurl'];
8
8
  const curlHandle = new Curl();
@@ -115,7 +115,8 @@ export function fetchCurl(fetchRequest) {
115
115
  .filter(headerFilter => {
116
116
  if (headerFilter && !headerFilter.startsWith('HTTP/')) {
117
117
  if (fetchRequest.redirect === 'error' &&
118
- (headerFilter.includes('location') || headerFilter.includes('Location'))) {
118
+ (headerFilter.includes('location') || headerFilter.includes('Location')) &&
119
+ shouldRedirect(status)) {
119
120
  if (!stream.destroyed) {
120
121
  stream.resume();
121
122
  }
@@ -6,7 +6,7 @@ import { createBrotliDecompress, createGunzip, createInflate, createInflateRaw }
6
6
  import { PonyfillRequest } from './Request.js';
7
7
  import { PonyfillResponse } from './Response.js';
8
8
  import { PonyfillURL } from './URL.js';
9
- import { getHeadersObj, isNodeReadable } from './utils.js';
9
+ import { getHeadersObj, isNodeReadable, shouldRedirect } from './utils.js';
10
10
  function getRequestFnForProtocol(url) {
11
11
  if (url.startsWith('http:')) {
12
12
  return httpRequest;
@@ -70,7 +70,7 @@ export function fetchNodeHttp(fetchRequest) {
70
70
  default:
71
71
  outputStream = new PassThrough();
72
72
  }
73
- if (nodeResponse.headers.location) {
73
+ if (nodeResponse.headers.location && shouldRedirect(nodeResponse.statusCode)) {
74
74
  if (fetchRequest.redirect === 'error') {
75
75
  const redirectError = new Error('Redirects are not allowed');
76
76
  reject(redirectError);
package/esm/utils.js CHANGED
@@ -79,3 +79,6 @@ export function createDeferredPromise() {
79
79
  export function isIterable(value) {
80
80
  return value?.[Symbol.iterator] != null;
81
81
  }
82
+ export function shouldRedirect(status) {
83
+ return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
84
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.7.8",
3
+ "version": "0.7.9-alpha-20250213114401-de7d1130414fecb9eaf387c5024f8c53032fc246",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -11,3 +11,4 @@ export interface DeferredPromise<T = void> {
11
11
  }
12
12
  export declare function createDeferredPromise<T = void>(): DeferredPromise<T>;
13
13
  export declare function isIterable(value: any): value is Iterable<unknown>;
14
+ export declare function shouldRedirect(status?: number): boolean;
@@ -11,3 +11,4 @@ export interface DeferredPromise<T = void> {
11
11
  }
12
12
  export declare function createDeferredPromise<T = void>(): DeferredPromise<T>;
13
13
  export declare function isIterable(value: any): value is Iterable<unknown>;
14
+ export declare function shouldRedirect(status?: number): boolean;