@whatwg-node/node-fetch 0.7.17-alpha-20250325145529-58232171d1f56e9f26b72ecd5acfffe6680802dc → 0.7.17-alpha-20250325150348-7623243e301deb614f405fb2c602a77956d868a8
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/Body.js +2 -6
- package/cjs/fetchCurl.js +4 -11
- package/cjs/fetchNodeHttp.js +5 -10
- package/cjs/utils.js +18 -0
- package/esm/Body.js +4 -8
- package/esm/fetchCurl.js +6 -13
- package/esm/fetchNodeHttp.js +6 -11
- package/esm/utils.js +17 -0
- package/package.json +1 -1
- package/typings/utils.d.cts +8 -1
- package/typings/utils.d.ts +8 -1
package/cjs/Body.js
CHANGED
@@ -6,7 +6,6 @@ const tslib_1 = require("tslib");
|
|
6
6
|
const node_buffer_1 = require("node:buffer");
|
7
7
|
const node_http_1 = require("node:http");
|
8
8
|
const node_stream_1 = require("node:stream");
|
9
|
-
const promises_1 = require("node:stream/promises");
|
10
9
|
const busboy_1 = tslib_1.__importDefault(require("busboy"));
|
11
10
|
const promise_helpers_1 = require("@whatwg-node/promise-helpers");
|
12
11
|
const Blob_js_1 = require("./Blob.js");
|
@@ -402,12 +401,9 @@ function processBodyInit(bodyInit, signal) {
|
|
402
401
|
};
|
403
402
|
}
|
404
403
|
if (bodyInit instanceof node_http_1.IncomingMessage) {
|
405
|
-
const passThrough =
|
406
|
-
|
404
|
+
const passThrough = (0, utils_js_1.wrapIncomingMessageWithPassthrough)({
|
405
|
+
incomingMessage: bodyInit,
|
407
406
|
signal,
|
408
|
-
end: true,
|
409
|
-
}).catch(e => {
|
410
|
-
passThrough.destroy(e);
|
411
407
|
});
|
412
408
|
return {
|
413
409
|
bodyType: BodyInitType.Readable,
|
package/cjs/fetchCurl.js
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.fetchCurl = fetchCurl;
|
4
4
|
const node_stream_1 = require("node:stream");
|
5
|
-
const promises_1 = require("node:stream/promises");
|
6
5
|
const node_tls_1 = require("node:tls");
|
7
6
|
const promise_helpers_1 = require("@whatwg-node/promise-helpers");
|
8
7
|
const Response_js_1 = require("./Response.js");
|
@@ -102,17 +101,11 @@ function fetchCurl(fetchRequest) {
|
|
102
101
|
}
|
103
102
|
});
|
104
103
|
curlHandle.once('stream', function streamListener(stream, status, headersBuf) {
|
105
|
-
const outputStream =
|
106
|
-
|
107
|
-
end: true,
|
104
|
+
const outputStream = (0, utils_js_1.wrapIncomingMessageWithPassthrough)({
|
105
|
+
incomingMessage: stream,
|
108
106
|
signal: fetchRequest.signal,
|
109
|
-
|
110
|
-
|
111
|
-
if (!stream.destroyed) {
|
112
|
-
stream.resume();
|
113
|
-
}
|
114
|
-
})
|
115
|
-
.catch(deferredPromise.reject);
|
107
|
+
onError: deferredPromise.reject,
|
108
|
+
});
|
116
109
|
const headersFlat = headersBuf
|
117
110
|
.toString('utf8')
|
118
111
|
.split(/\r?\n|\r/g)
|
package/cjs/fetchNodeHttp.js
CHANGED
@@ -4,7 +4,6 @@ exports.fetchNodeHttp = fetchNodeHttp;
|
|
4
4
|
const node_http_1 = require("node:http");
|
5
5
|
const node_https_1 = require("node:https");
|
6
6
|
const node_stream_1 = require("node:stream");
|
7
|
-
const promises_1 = require("node:stream/promises");
|
8
7
|
const node_zlib_1 = require("node:zlib");
|
9
8
|
const Request_js_1 = require("./Request.js");
|
10
9
|
const Response_js_1 = require("./Response.js");
|
@@ -85,16 +84,12 @@ function fetchNodeHttp(fetchRequest) {
|
|
85
84
|
}
|
86
85
|
}
|
87
86
|
if (outputStream != null) {
|
88
|
-
(0,
|
87
|
+
outputStream = (0, utils_js_1.wrapIncomingMessageWithPassthrough)({
|
88
|
+
incomingMessage: nodeResponse,
|
89
|
+
passThrough: outputStream,
|
89
90
|
signal: fetchRequest.signal,
|
90
|
-
|
91
|
-
})
|
92
|
-
.then(() => {
|
93
|
-
if (!nodeResponse.destroyed) {
|
94
|
-
nodeResponse.resume();
|
95
|
-
}
|
96
|
-
})
|
97
|
-
.catch(reject);
|
91
|
+
onError: reject,
|
92
|
+
});
|
98
93
|
}
|
99
94
|
const statusCode = nodeResponse.statusCode || 200;
|
100
95
|
let statusText = nodeResponse.statusMessage || node_http_1.STATUS_CODES[statusCode];
|
package/cjs/utils.js
CHANGED
@@ -7,6 +7,9 @@ exports.isArrayBufferView = isArrayBufferView;
|
|
7
7
|
exports.isNodeReadable = isNodeReadable;
|
8
8
|
exports.isIterable = isIterable;
|
9
9
|
exports.shouldRedirect = shouldRedirect;
|
10
|
+
exports.wrapIncomingMessageWithPassthrough = wrapIncomingMessageWithPassthrough;
|
11
|
+
const node_stream_1 = require("node:stream");
|
12
|
+
const promises_1 = require("node:stream/promises");
|
10
13
|
function isHeadersInstance(obj) {
|
11
14
|
return obj?.forEach != null;
|
12
15
|
}
|
@@ -40,3 +43,18 @@ function isIterable(value) {
|
|
40
43
|
function shouldRedirect(status) {
|
41
44
|
return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
|
42
45
|
}
|
46
|
+
function wrapIncomingMessageWithPassthrough({ incomingMessage, signal, passThrough = new node_stream_1.PassThrough(), onError = (e) => {
|
47
|
+
passThrough.destroy(e);
|
48
|
+
}, }) {
|
49
|
+
(0, promises_1.pipeline)(incomingMessage, passThrough, {
|
50
|
+
signal,
|
51
|
+
end: true,
|
52
|
+
})
|
53
|
+
.then(() => {
|
54
|
+
if (!incomingMessage.destroyed) {
|
55
|
+
incomingMessage.resume();
|
56
|
+
}
|
57
|
+
})
|
58
|
+
.catch(onError);
|
59
|
+
return passThrough;
|
60
|
+
}
|
package/esm/Body.js
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
2
2
|
import { Buffer } from 'node:buffer';
|
3
3
|
import { IncomingMessage } from 'node:http';
|
4
|
-
import {
|
5
|
-
import { pipeline } from 'node:stream/promises';
|
4
|
+
import { Readable } from 'node:stream';
|
6
5
|
import busboy from 'busboy';
|
7
6
|
import { handleMaybePromise } from '@whatwg-node/promise-helpers';
|
8
7
|
import { hasArrayBufferMethod, hasBufferMethod, hasBytesMethod, PonyfillBlob } from './Blob.js';
|
9
8
|
import { PonyfillFile } from './File.js';
|
10
9
|
import { getStreamFromFormData, PonyfillFormData } from './FormData.js';
|
11
10
|
import { PonyfillReadableStream } from './ReadableStream.js';
|
12
|
-
import { fakePromise, isArrayBufferView } from './utils.js';
|
11
|
+
import { fakePromise, isArrayBufferView, wrapIncomingMessageWithPassthrough } from './utils.js';
|
13
12
|
var BodyInitType;
|
14
13
|
(function (BodyInitType) {
|
15
14
|
BodyInitType["ReadableStream"] = "ReadableStream";
|
@@ -397,12 +396,9 @@ function processBodyInit(bodyInit, signal) {
|
|
397
396
|
};
|
398
397
|
}
|
399
398
|
if (bodyInit instanceof IncomingMessage) {
|
400
|
-
const passThrough =
|
401
|
-
|
399
|
+
const passThrough = wrapIncomingMessageWithPassthrough({
|
400
|
+
incomingMessage: bodyInit,
|
402
401
|
signal,
|
403
|
-
end: true,
|
404
|
-
}).catch(e => {
|
405
|
-
passThrough.destroy(e);
|
406
402
|
});
|
407
403
|
return {
|
408
404
|
bodyType: BodyInitType.Readable,
|
package/esm/fetchCurl.js
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
import {
|
2
|
-
import { pipeline } from 'node:stream/promises';
|
1
|
+
import { Readable } from 'node:stream';
|
3
2
|
import { rootCertificates } from 'node:tls';
|
4
3
|
import { createDeferredPromise } from '@whatwg-node/promise-helpers';
|
5
4
|
import { PonyfillResponse } from './Response.js';
|
6
|
-
import { defaultHeadersSerializer, isNodeReadable, shouldRedirect } from './utils.js';
|
5
|
+
import { defaultHeadersSerializer, isNodeReadable, shouldRedirect, wrapIncomingMessageWithPassthrough, } from './utils.js';
|
7
6
|
export function fetchCurl(fetchRequest) {
|
8
7
|
const { Curl, CurlFeature, CurlPause, CurlProgressFunc } = globalThis['libcurl'];
|
9
8
|
const curlHandle = new Curl();
|
@@ -99,17 +98,11 @@ export function fetchCurl(fetchRequest) {
|
|
99
98
|
}
|
100
99
|
});
|
101
100
|
curlHandle.once('stream', function streamListener(stream, status, headersBuf) {
|
102
|
-
const outputStream =
|
103
|
-
|
104
|
-
end: true,
|
101
|
+
const outputStream = wrapIncomingMessageWithPassthrough({
|
102
|
+
incomingMessage: stream,
|
105
103
|
signal: fetchRequest.signal,
|
106
|
-
|
107
|
-
|
108
|
-
if (!stream.destroyed) {
|
109
|
-
stream.resume();
|
110
|
-
}
|
111
|
-
})
|
112
|
-
.catch(deferredPromise.reject);
|
104
|
+
onError: deferredPromise.reject,
|
105
|
+
});
|
113
106
|
const headersFlat = headersBuf
|
114
107
|
.toString('utf8')
|
115
108
|
.split(/\r?\n|\r/g)
|
package/esm/fetchNodeHttp.js
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
import { request as httpRequest, STATUS_CODES } from 'node:http';
|
2
2
|
import { request as httpsRequest } from 'node:https';
|
3
3
|
import { Readable } from 'node:stream';
|
4
|
-
import { pipeline } from 'node:stream/promises';
|
5
4
|
import { createBrotliDecompress, createGunzip, createInflate, createInflateRaw } from 'node:zlib';
|
6
5
|
import { PonyfillRequest } from './Request.js';
|
7
6
|
import { PonyfillResponse } from './Response.js';
|
8
7
|
import { PonyfillURL } from './URL.js';
|
9
|
-
import { getHeadersObj, isNodeReadable, shouldRedirect } from './utils.js';
|
8
|
+
import { getHeadersObj, isNodeReadable, shouldRedirect, wrapIncomingMessageWithPassthrough, } from './utils.js';
|
10
9
|
function getRequestFnForProtocol(url) {
|
11
10
|
if (url.startsWith('http:')) {
|
12
11
|
return httpRequest;
|
@@ -82,16 +81,12 @@ export function fetchNodeHttp(fetchRequest) {
|
|
82
81
|
}
|
83
82
|
}
|
84
83
|
if (outputStream != null) {
|
85
|
-
|
84
|
+
outputStream = wrapIncomingMessageWithPassthrough({
|
85
|
+
incomingMessage: nodeResponse,
|
86
|
+
passThrough: outputStream,
|
86
87
|
signal: fetchRequest.signal,
|
87
|
-
|
88
|
-
})
|
89
|
-
.then(() => {
|
90
|
-
if (!nodeResponse.destroyed) {
|
91
|
-
nodeResponse.resume();
|
92
|
-
}
|
93
|
-
})
|
94
|
-
.catch(reject);
|
88
|
+
onError: reject,
|
89
|
+
});
|
95
90
|
}
|
96
91
|
const statusCode = nodeResponse.statusCode || 200;
|
97
92
|
let statusText = nodeResponse.statusMessage || STATUS_CODES[statusCode];
|
package/esm/utils.js
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
import { PassThrough } from 'node:stream';
|
2
|
+
import { pipeline } from 'node:stream/promises';
|
1
3
|
function isHeadersInstance(obj) {
|
2
4
|
return obj?.forEach != null;
|
3
5
|
}
|
@@ -30,3 +32,18 @@ export function isIterable(value) {
|
|
30
32
|
export function shouldRedirect(status) {
|
31
33
|
return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
|
32
34
|
}
|
35
|
+
export function wrapIncomingMessageWithPassthrough({ incomingMessage, signal, passThrough = new PassThrough(), onError = (e) => {
|
36
|
+
passThrough.destroy(e);
|
37
|
+
}, }) {
|
38
|
+
pipeline(incomingMessage, passThrough, {
|
39
|
+
signal,
|
40
|
+
end: true,
|
41
|
+
})
|
42
|
+
.then(() => {
|
43
|
+
if (!incomingMessage.destroyed) {
|
44
|
+
incomingMessage.resume();
|
45
|
+
}
|
46
|
+
})
|
47
|
+
.catch(onError);
|
48
|
+
return passThrough;
|
49
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@whatwg-node/node-fetch",
|
3
|
-
"version": "0.7.17-alpha-
|
3
|
+
"version": "0.7.17-alpha-20250325150348-7623243e301deb614f405fb2c602a77956d868a8",
|
4
4
|
"description": "Fetch API implementation for Node",
|
5
5
|
"sideEffects": false,
|
6
6
|
"dependencies": {
|
package/typings/utils.d.cts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
import {
|
1
|
+
import { IncomingMessage } from 'node:http';
|
2
|
+
import { PassThrough, Readable } from 'node:stream';
|
2
3
|
export declare function getHeadersObj(headers: Headers): Record<string, string>;
|
3
4
|
export declare function defaultHeadersSerializer(headers: Headers, onContentLength?: (value: string) => void): string[];
|
4
5
|
export { fakePromise } from '@whatwg-node/promise-helpers';
|
@@ -6,3 +7,9 @@ export declare function isArrayBufferView(obj: any): obj is ArrayBufferView;
|
|
6
7
|
export declare function isNodeReadable(obj: any): obj is Readable;
|
7
8
|
export declare function isIterable(value: any): value is Iterable<unknown>;
|
8
9
|
export declare function shouldRedirect(status?: number): boolean;
|
10
|
+
export declare function wrapIncomingMessageWithPassthrough({ incomingMessage, signal, passThrough, onError, }: {
|
11
|
+
incomingMessage: IncomingMessage;
|
12
|
+
passThrough?: PassThrough | undefined;
|
13
|
+
signal?: AbortSignal | undefined;
|
14
|
+
onError?: (e: Error) => void;
|
15
|
+
}): PassThrough;
|
package/typings/utils.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
import {
|
1
|
+
import { IncomingMessage } from 'node:http';
|
2
|
+
import { PassThrough, Readable } from 'node:stream';
|
2
3
|
export declare function getHeadersObj(headers: Headers): Record<string, string>;
|
3
4
|
export declare function defaultHeadersSerializer(headers: Headers, onContentLength?: (value: string) => void): string[];
|
4
5
|
export { fakePromise } from '@whatwg-node/promise-helpers';
|
@@ -6,3 +7,9 @@ export declare function isArrayBufferView(obj: any): obj is ArrayBufferView;
|
|
6
7
|
export declare function isNodeReadable(obj: any): obj is Readable;
|
7
8
|
export declare function isIterable(value: any): value is Iterable<unknown>;
|
8
9
|
export declare function shouldRedirect(status?: number): boolean;
|
10
|
+
export declare function wrapIncomingMessageWithPassthrough({ incomingMessage, signal, passThrough, onError, }: {
|
11
|
+
incomingMessage: IncomingMessage;
|
12
|
+
passThrough?: PassThrough | undefined;
|
13
|
+
signal?: AbortSignal | undefined;
|
14
|
+
onError?: (e: Error) => void;
|
15
|
+
}): PassThrough;
|