@whatwg-node/node-fetch 0.5.7-alpha-20240301155147-161016a5c5b719972dd96f47adc3ee3be99e11d4 → 0.5.7-alpha-20240301160930-a3ba2c27f4f23de94960f603ed19b24325dfe24d
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 +11 -2
- package/cjs/fetchNodeHttp.js +12 -3
- package/cjs/utils.js +1 -7
- package/esm/fetchCurl.js +13 -4
- package/esm/fetchNodeHttp.js +14 -5
- package/esm/utils.js +0 -6
- package/package.json +1 -1
- package/typings/utils.d.cts +0 -1
- package/typings/utils.d.ts +0 -1
package/cjs/fetchCurl.js
CHANGED
@@ -88,12 +88,21 @@ function fetchCurl(fetchRequest) {
|
|
88
88
|
return false;
|
89
89
|
});
|
90
90
|
const headersInit = headersFlat.map(headerFlat => headerFlat.split(/:\s(.+)/).slice(0, 2));
|
91
|
-
const
|
91
|
+
const pipedStream = stream.pipe(new node_stream_1.PassThrough());
|
92
|
+
pipedStream.on('pause', () => {
|
93
|
+
stream.pause();
|
94
|
+
});
|
95
|
+
pipedStream.on('resume', () => {
|
96
|
+
stream.resume();
|
97
|
+
});
|
98
|
+
pipedStream.on('close', () => {
|
99
|
+
stream.destroy();
|
100
|
+
});
|
101
|
+
const ponyfillResponse = new Response_js_1.PonyfillResponse(pipedStream, {
|
92
102
|
status,
|
93
103
|
headers: headersInit,
|
94
104
|
url: fetchRequest.url,
|
95
105
|
});
|
96
|
-
utils_js_1.readableCleanupRegistry.register(ponyfillResponse, stream);
|
97
106
|
resolve(ponyfillResponse);
|
98
107
|
streamResolved = stream;
|
99
108
|
});
|
package/cjs/fetchNodeHttp.js
CHANGED
@@ -69,15 +69,24 @@ function fetchNodeHttp(fetchRequest) {
|
|
69
69
|
return;
|
70
70
|
}
|
71
71
|
}
|
72
|
+
if (responseBody === nodeResponse) {
|
73
|
+
responseBody = nodeResponse.pipe(new stream_1.PassThrough());
|
74
|
+
responseBody.on('pause', () => {
|
75
|
+
nodeResponse.pause();
|
76
|
+
});
|
77
|
+
responseBody.on('resume', () => {
|
78
|
+
nodeResponse.resume();
|
79
|
+
});
|
80
|
+
responseBody.on('close', () => {
|
81
|
+
nodeResponse.destroy();
|
82
|
+
});
|
83
|
+
}
|
72
84
|
const ponyfillResponse = new Response_js_1.PonyfillResponse(responseBody, {
|
73
85
|
status: nodeResponse.statusCode,
|
74
86
|
statusText: nodeResponse.statusMessage,
|
75
87
|
headers: nodeResponse.headers,
|
76
88
|
url: fetchRequest.url,
|
77
89
|
});
|
78
|
-
if (responseBody === nodeResponse) {
|
79
|
-
utils_js_1.readableCleanupRegistry.register(ponyfillResponse, nodeResponse);
|
80
|
-
}
|
81
90
|
resolve(ponyfillResponse);
|
82
91
|
});
|
83
92
|
nodeRequest.once('error', reject);
|
package/cjs/utils.js
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
4
|
-
const node_stream_1 = require("node:stream");
|
3
|
+
exports.isNodeReadable = exports.isArrayBufferView = exports.fakePromise = exports.defaultHeadersSerializer = exports.getHeadersObj = void 0;
|
5
4
|
function isHeadersInstance(obj) {
|
6
5
|
return obj?.forEach != null;
|
7
6
|
}
|
@@ -72,8 +71,3 @@ function isNodeReadable(obj) {
|
|
72
71
|
return obj != null && obj.pipe != null;
|
73
72
|
}
|
74
73
|
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 { Readable } from 'node:stream';
|
1
|
+
import { PassThrough, Readable } from 'node:stream';
|
2
2
|
import { PonyfillResponse } from './Response.js';
|
3
|
-
import { defaultHeadersSerializer, isNodeReadable
|
3
|
+
import { defaultHeadersSerializer, isNodeReadable } 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,12 +85,21 @@ export function fetchCurl(fetchRequest) {
|
|
85
85
|
return false;
|
86
86
|
});
|
87
87
|
const headersInit = headersFlat.map(headerFlat => headerFlat.split(/:\s(.+)/).slice(0, 2));
|
88
|
-
const
|
88
|
+
const pipedStream = stream.pipe(new PassThrough());
|
89
|
+
pipedStream.on('pause', () => {
|
90
|
+
stream.pause();
|
91
|
+
});
|
92
|
+
pipedStream.on('resume', () => {
|
93
|
+
stream.resume();
|
94
|
+
});
|
95
|
+
pipedStream.on('close', () => {
|
96
|
+
stream.destroy();
|
97
|
+
});
|
98
|
+
const ponyfillResponse = new PonyfillResponse(pipedStream, {
|
89
99
|
status,
|
90
100
|
headers: headersInit,
|
91
101
|
url: fetchRequest.url,
|
92
102
|
});
|
93
|
-
readableCleanupRegistry.register(ponyfillResponse, stream);
|
94
103
|
resolve(ponyfillResponse);
|
95
104
|
streamResolved = stream;
|
96
105
|
});
|
package/esm/fetchNodeHttp.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
import { request as httpRequest } from 'http';
|
2
2
|
import { request as httpsRequest } from 'https';
|
3
|
-
import { Readable } from 'stream';
|
3
|
+
import { PassThrough, 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
|
8
|
+
import { getHeadersObj, isNodeReadable } from './utils.js';
|
9
9
|
function getRequestFnForProtocol(url) {
|
10
10
|
if (url.startsWith('http:')) {
|
11
11
|
return httpRequest;
|
@@ -66,15 +66,24 @@ export function fetchNodeHttp(fetchRequest) {
|
|
66
66
|
return;
|
67
67
|
}
|
68
68
|
}
|
69
|
+
if (responseBody === nodeResponse) {
|
70
|
+
responseBody = nodeResponse.pipe(new PassThrough());
|
71
|
+
responseBody.on('pause', () => {
|
72
|
+
nodeResponse.pause();
|
73
|
+
});
|
74
|
+
responseBody.on('resume', () => {
|
75
|
+
nodeResponse.resume();
|
76
|
+
});
|
77
|
+
responseBody.on('close', () => {
|
78
|
+
nodeResponse.destroy();
|
79
|
+
});
|
80
|
+
}
|
69
81
|
const ponyfillResponse = new PonyfillResponse(responseBody, {
|
70
82
|
status: nodeResponse.statusCode,
|
71
83
|
statusText: nodeResponse.statusMessage,
|
72
84
|
headers: nodeResponse.headers,
|
73
85
|
url: fetchRequest.url,
|
74
86
|
});
|
75
|
-
if (responseBody === nodeResponse) {
|
76
|
-
readableCleanupRegistry.register(ponyfillResponse, nodeResponse);
|
77
|
-
}
|
78
87
|
resolve(ponyfillResponse);
|
79
88
|
});
|
80
89
|
nodeRequest.once('error', reject);
|
package/esm/utils.js
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import { PassThrough } from 'node:stream';
|
2
1
|
function isHeadersInstance(obj) {
|
3
2
|
return obj?.forEach != null;
|
4
3
|
}
|
@@ -64,8 +63,3 @@ export function isArrayBufferView(obj) {
|
|
64
63
|
export function isNodeReadable(obj) {
|
65
64
|
return obj != null && obj.pipe != null;
|
66
65
|
}
|
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-
|
3
|
+
"version": "0.5.7-alpha-20240301160930-a3ba2c27f4f23de94960f603ed19b24325dfe24d",
|
4
4
|
"description": "Fetch API implementation for Node",
|
5
5
|
"sideEffects": false,
|
6
6
|
"dependencies": {
|
package/typings/utils.d.cts
CHANGED
@@ -5,4 +5,3 @@ 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>;
|
package/typings/utils.d.ts
CHANGED
@@ -5,4 +5,3 @@ 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>;
|