@whatwg-node/node-fetch 0.7.24 → 0.7.25-alpha-20250729225623-2377d384db01c30592dffc1bb6248bc3baa4502c

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.
@@ -92,21 +92,22 @@ function fetchNodeHttp(fetchRequest) {
92
92
  return;
93
93
  }
94
94
  }
95
- outputStream ||= new node_stream_1.PassThrough();
96
- (0, utils_js_1.pipeThrough)({
97
- src: nodeResponse,
98
- dest: outputStream,
99
- signal,
100
- onError: e => {
101
- if (!nodeResponse.destroyed) {
102
- nodeResponse.destroy(e);
103
- }
104
- if (!outputStream.destroyed) {
105
- outputStream.destroy(e);
106
- }
107
- reject(e);
108
- },
109
- });
95
+ if (outputStream) {
96
+ (0, utils_js_1.pipeThrough)({
97
+ src: nodeResponse,
98
+ dest: outputStream,
99
+ signal,
100
+ onError: e => {
101
+ if (!nodeResponse.destroyed) {
102
+ nodeResponse.destroy(e);
103
+ }
104
+ if (!outputStream.destroyed) {
105
+ outputStream.destroy(e);
106
+ }
107
+ reject(e);
108
+ },
109
+ });
110
+ }
110
111
  const statusCode = nodeResponse.statusCode || 200;
111
112
  let statusText = nodeResponse.statusMessage || node_http_1.STATUS_CODES[statusCode];
112
113
  if (statusText == null) {
@@ -119,6 +120,7 @@ function fetchNodeHttp(fetchRequest) {
119
120
  url: fetchRequest.url,
120
121
  signal,
121
122
  });
123
+ finalizationRegistry.register(ponyfillResponse, nodeResponse);
122
124
  resolve(ponyfillResponse);
123
125
  });
124
126
  if (fetchRequest['_buffer'] != null) {
@@ -143,3 +145,8 @@ function fetchNodeHttp(fetchRequest) {
143
145
  }
144
146
  });
145
147
  }
148
+ const finalizationRegistry = new FinalizationRegistry(incomingMessage => {
149
+ if (!incomingMessage.destroyed) {
150
+ incomingMessage.destroy();
151
+ }
152
+ });
@@ -1,6 +1,6 @@
1
1
  import { request as httpRequest, STATUS_CODES } from 'node:http';
2
2
  import { request as httpsRequest } from 'node:https';
3
- import { PassThrough, Readable } from 'node:stream';
3
+ import { Readable } from 'node:stream';
4
4
  import { createBrotliDecompress, createGunzip, createInflate, createInflateRaw } from 'node:zlib';
5
5
  import { handleMaybePromise } from '@whatwg-node/promise-helpers';
6
6
  import { PonyfillRequest } from './Request.js';
@@ -89,21 +89,22 @@ export function fetchNodeHttp(fetchRequest) {
89
89
  return;
90
90
  }
91
91
  }
92
- outputStream ||= new PassThrough();
93
- pipeThrough({
94
- src: nodeResponse,
95
- dest: outputStream,
96
- signal,
97
- onError: e => {
98
- if (!nodeResponse.destroyed) {
99
- nodeResponse.destroy(e);
100
- }
101
- if (!outputStream.destroyed) {
102
- outputStream.destroy(e);
103
- }
104
- reject(e);
105
- },
106
- });
92
+ if (outputStream) {
93
+ pipeThrough({
94
+ src: nodeResponse,
95
+ dest: outputStream,
96
+ signal,
97
+ onError: e => {
98
+ if (!nodeResponse.destroyed) {
99
+ nodeResponse.destroy(e);
100
+ }
101
+ if (!outputStream.destroyed) {
102
+ outputStream.destroy(e);
103
+ }
104
+ reject(e);
105
+ },
106
+ });
107
+ }
107
108
  const statusCode = nodeResponse.statusCode || 200;
108
109
  let statusText = nodeResponse.statusMessage || STATUS_CODES[statusCode];
109
110
  if (statusText == null) {
@@ -116,6 +117,7 @@ export function fetchNodeHttp(fetchRequest) {
116
117
  url: fetchRequest.url,
117
118
  signal,
118
119
  });
120
+ finalizationRegistry.register(ponyfillResponse, nodeResponse);
119
121
  resolve(ponyfillResponse);
120
122
  });
121
123
  if (fetchRequest['_buffer'] != null) {
@@ -140,3 +142,8 @@ export function fetchNodeHttp(fetchRequest) {
140
142
  }
141
143
  });
142
144
  }
145
+ const finalizationRegistry = new FinalizationRegistry(incomingMessage => {
146
+ if (!incomingMessage.destroyed) {
147
+ incomingMessage.destroy();
148
+ }
149
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.7.24",
3
+ "version": "0.7.25-alpha-20250729225623-2377d384db01c30592dffc1bb6248bc3baa4502c",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {