@whatwg-node/node-fetch 0.5.7-alpha-20240229132341-1e3c1f24effefed571297b2c5001e44cfaefbf60 → 0.5.7-alpha-20240301155147-161016a5c5b719972dd96f47adc3ee3be99e11d4

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
@@ -88,11 +88,13 @@ function fetchCurl(fetchRequest) {
88
88
  return false;
89
89
  });
90
90
  const headersInit = headersFlat.map(headerFlat => headerFlat.split(/:\s(.+)/).slice(0, 2));
91
- resolve(new Response_js_1.PonyfillResponse(stream.pipe(new node_stream_1.PassThrough()), {
91
+ const ponyfillResponse = new Response_js_1.PonyfillResponse(stream, {
92
92
  status,
93
93
  headers: headersInit,
94
94
  url: fetchRequest.url,
95
- }));
95
+ });
96
+ utils_js_1.readableCleanupRegistry.register(ponyfillResponse, stream);
97
+ resolve(ponyfillResponse);
96
98
  streamResolved = stream;
97
99
  });
98
100
  curlHandle.perform();
@@ -36,7 +36,7 @@ function fetchNodeHttp(fetchRequest) {
36
36
  agent: fetchRequest.agent,
37
37
  });
38
38
  nodeRequest.once('response', nodeResponse => {
39
- let responseBody = nodeResponse.pipe(new stream_1.PassThrough());
39
+ let responseBody = nodeResponse;
40
40
  const contentEncoding = nodeResponse.headers['content-encoding'];
41
41
  switch (contentEncoding) {
42
42
  case 'x-gzip':
@@ -75,6 +75,9 @@ function fetchNodeHttp(fetchRequest) {
75
75
  headers: nodeResponse.headers,
76
76
  url: fetchRequest.url,
77
77
  });
78
+ if (responseBody === nodeResponse) {
79
+ utils_js_1.readableCleanupRegistry.register(ponyfillResponse, nodeResponse);
80
+ }
78
81
  resolve(ponyfillResponse);
79
82
  });
80
83
  nodeRequest.once('error', reject);
package/cjs/utils.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNodeReadable = exports.isArrayBufferView = exports.fakePromise = exports.defaultHeadersSerializer = exports.getHeadersObj = void 0;
3
+ exports.readableCleanupRegistry = exports.isNodeReadable = exports.isArrayBufferView = exports.fakePromise = exports.defaultHeadersSerializer = exports.getHeadersObj = void 0;
4
+ const node_stream_1 = require("node:stream");
4
5
  function isHeadersInstance(obj) {
5
6
  return obj?.forEach != null;
6
7
  }
@@ -71,3 +72,8 @@ function isNodeReadable(obj) {
71
72
  return obj != null && obj.pipe != null;
72
73
  }
73
74
  exports.isNodeReadable = isNodeReadable;
75
+ exports.readableCleanupRegistry = new FinalizationRegistry(readable => {
76
+ if (!readable.readableFlowing) {
77
+ readable.pipe(new node_stream_1.PassThrough());
78
+ }
79
+ });
package/esm/fetchCurl.js CHANGED
@@ -1,6 +1,6 @@
1
- import { PassThrough, Readable } from 'node:stream';
1
+ import { Readable } from 'node:stream';
2
2
  import { PonyfillResponse } from './Response.js';
3
- import { defaultHeadersSerializer, isNodeReadable } from './utils.js';
3
+ import { defaultHeadersSerializer, isNodeReadable, readableCleanupRegistry } from './utils.js';
4
4
  export function fetchCurl(fetchRequest) {
5
5
  const { Curl, CurlFeature, CurlPause, CurlProgressFunc } = globalThis['libcurl'];
6
6
  const curlHandle = new Curl();
@@ -85,11 +85,13 @@ export function fetchCurl(fetchRequest) {
85
85
  return false;
86
86
  });
87
87
  const headersInit = headersFlat.map(headerFlat => headerFlat.split(/:\s(.+)/).slice(0, 2));
88
- resolve(new PonyfillResponse(stream.pipe(new PassThrough()), {
88
+ const ponyfillResponse = new PonyfillResponse(stream, {
89
89
  status,
90
90
  headers: headersInit,
91
91
  url: fetchRequest.url,
92
- }));
92
+ });
93
+ readableCleanupRegistry.register(ponyfillResponse, stream);
94
+ resolve(ponyfillResponse);
93
95
  streamResolved = stream;
94
96
  });
95
97
  curlHandle.perform();
@@ -1,11 +1,11 @@
1
1
  import { request as httpRequest } from 'http';
2
2
  import { request as httpsRequest } from 'https';
3
- import { PassThrough, Readable } from 'stream';
3
+ import { Readable } from 'stream';
4
4
  import { createBrotliDecompress, createGunzip, createInflate } from 'zlib';
5
5
  import { PonyfillRequest } from './Request.js';
6
6
  import { PonyfillResponse } from './Response.js';
7
7
  import { PonyfillURL } from './URL.js';
8
- import { getHeadersObj, isNodeReadable } from './utils.js';
8
+ import { getHeadersObj, isNodeReadable, readableCleanupRegistry } from './utils.js';
9
9
  function getRequestFnForProtocol(url) {
10
10
  if (url.startsWith('http:')) {
11
11
  return httpRequest;
@@ -33,7 +33,7 @@ export function fetchNodeHttp(fetchRequest) {
33
33
  agent: fetchRequest.agent,
34
34
  });
35
35
  nodeRequest.once('response', nodeResponse => {
36
- let responseBody = nodeResponse.pipe(new PassThrough());
36
+ let responseBody = nodeResponse;
37
37
  const contentEncoding = nodeResponse.headers['content-encoding'];
38
38
  switch (contentEncoding) {
39
39
  case 'x-gzip':
@@ -72,6 +72,9 @@ export function fetchNodeHttp(fetchRequest) {
72
72
  headers: nodeResponse.headers,
73
73
  url: fetchRequest.url,
74
74
  });
75
+ if (responseBody === nodeResponse) {
76
+ readableCleanupRegistry.register(ponyfillResponse, nodeResponse);
77
+ }
75
78
  resolve(ponyfillResponse);
76
79
  });
77
80
  nodeRequest.once('error', reject);
package/esm/utils.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { PassThrough } from 'node:stream';
1
2
  function isHeadersInstance(obj) {
2
3
  return obj?.forEach != null;
3
4
  }
@@ -63,3 +64,8 @@ export function isArrayBufferView(obj) {
63
64
  export function isNodeReadable(obj) {
64
65
  return obj != null && obj.pipe != null;
65
66
  }
67
+ export const readableCleanupRegistry = new FinalizationRegistry(readable => {
68
+ if (!readable.readableFlowing) {
69
+ readable.pipe(new PassThrough());
70
+ }
71
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.5.7-alpha-20240229132341-1e3c1f24effefed571297b2c5001e44cfaefbf60",
3
+ "version": "0.5.7-alpha-20240301155147-161016a5c5b719972dd96f47adc3ee3be99e11d4",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -5,3 +5,4 @@ export declare function defaultHeadersSerializer(headers: Headers, onContentLeng
5
5
  export declare function fakePromise<T>(value: T): Promise<T>;
6
6
  export declare function isArrayBufferView(obj: any): obj is ArrayBufferView;
7
7
  export declare function isNodeReadable(obj: any): obj is Readable;
8
+ export declare const readableCleanupRegistry: FinalizationRegistry<Readable>;
@@ -5,3 +5,4 @@ export declare function defaultHeadersSerializer(headers: Headers, onContentLeng
5
5
  export declare function fakePromise<T>(value: T): Promise<T>;
6
6
  export declare function isArrayBufferView(obj: any): obj is ArrayBufferView;
7
7
  export declare function isNodeReadable(obj: any): obj is Readable;
8
+ export declare const readableCleanupRegistry: FinalizationRegistry<Readable>;