@whatwg-node/node-fetch 0.7.20-alpha-20250513160926-dc3cffd16372b805b6e089654d0af93f6a0fb544 → 0.7.20-alpha-20250513235048-f0d1b73cf44dc6870290e4a0cbd4b996a4225a62
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 +4 -4
- package/cjs/Request.js +4 -2
- package/cjs/Response.js +0 -1
- package/cjs/fetchCurl.js +14 -8
- package/cjs/fetchNodeHttp.js +15 -5
- package/esm/Body.js +4 -4
- package/esm/Request.js +4 -2
- package/esm/Response.js +0 -1
- package/esm/fetchCurl.js +14 -8
- package/esm/fetchNodeHttp.js +15 -5
- package/package.json +1 -1
- package/typings/Body.d.cts +2 -2
- package/typings/Body.d.ts +2 -2
- package/typings/Request.d.cts +1 -1
- package/typings/Request.d.ts +1 -1
package/cjs/Body.js
CHANGED
@@ -28,11 +28,11 @@ class PonyfillBody {
|
|
28
28
|
bodyUsed = false;
|
29
29
|
contentType = null;
|
30
30
|
contentLength = null;
|
31
|
-
|
31
|
+
_signal = null;
|
32
32
|
constructor(bodyInit, options = {}) {
|
33
33
|
this.bodyInit = bodyInit;
|
34
34
|
this.options = options;
|
35
|
-
this.
|
35
|
+
this._signal = options.signal || null;
|
36
36
|
const { bodyFactory, contentType, contentLength, bodyType, buffer } = processBodyInit(bodyInit, options?.signal);
|
37
37
|
this._bodyFactory = bodyFactory;
|
38
38
|
this.contentType = contentType;
|
@@ -205,8 +205,8 @@ class PonyfillBody {
|
|
205
205
|
limits: formDataLimits,
|
206
206
|
defCharset: 'utf-8',
|
207
207
|
});
|
208
|
-
if (this.
|
209
|
-
(0, node_stream_1.addAbortSignal)(this.
|
208
|
+
if (this._signal) {
|
209
|
+
(0, node_stream_1.addAbortSignal)(this._signal, bb);
|
210
210
|
}
|
211
211
|
let completed = false;
|
212
212
|
const complete = (err) => {
|
package/cjs/Request.js
CHANGED
@@ -57,7 +57,6 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
|
|
57
57
|
this.redirect = requestInit?.redirect || 'follow';
|
58
58
|
this.referrer = requestInit?.referrer || 'about:client';
|
59
59
|
this.referrerPolicy = requestInit?.referrerPolicy || 'no-referrer';
|
60
|
-
this.signal = requestInit?.signal || new AbortController().signal;
|
61
60
|
this.headersSerializer = requestInit?.headersSerializer;
|
62
61
|
this.duplex = requestInit?.duplex || 'half';
|
63
62
|
this.destination = 'document';
|
@@ -92,6 +91,10 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
|
|
92
91
|
referrer;
|
93
92
|
referrerPolicy;
|
94
93
|
_url;
|
94
|
+
get signal() {
|
95
|
+
this._signal ||= new AbortController().signal;
|
96
|
+
return this._signal;
|
97
|
+
}
|
95
98
|
get url() {
|
96
99
|
if (this._url == null) {
|
97
100
|
if (this._parsedUrl) {
|
@@ -117,7 +120,6 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
|
|
117
120
|
}
|
118
121
|
duplex;
|
119
122
|
agent;
|
120
|
-
signal;
|
121
123
|
clone() {
|
122
124
|
return this;
|
123
125
|
}
|
package/cjs/Response.js
CHANGED
@@ -18,7 +18,6 @@ class PonyfillResponse extends Body_js_1.PonyfillBody {
|
|
18
18
|
this.url = init?.url || '';
|
19
19
|
this.redirected = init?.redirected || false;
|
20
20
|
this.type = init?.type || 'default';
|
21
|
-
this.signal = init?.signal || null;
|
22
21
|
this.handleContentLengthHeader();
|
23
22
|
}
|
24
23
|
get ok() {
|
package/cjs/fetchCurl.js
CHANGED
@@ -21,8 +21,18 @@ function fetchCurl(fetchRequest) {
|
|
21
21
|
curlHandle.setOpt('CAINFO_BLOB', node_tls_1.rootCertificates.join('\n'));
|
22
22
|
}
|
23
23
|
curlHandle.enable(CurlFeature.StreamResponse);
|
24
|
+
let signal;
|
25
|
+
if (fetchRequest._signal === null) {
|
26
|
+
signal = undefined;
|
27
|
+
}
|
28
|
+
else if (fetchRequest._signal) {
|
29
|
+
signal = fetchRequest._signal;
|
30
|
+
}
|
31
|
+
else {
|
32
|
+
signal = fetchRequest.signal;
|
33
|
+
}
|
24
34
|
curlHandle.setStreamProgressCallback(function () {
|
25
|
-
return
|
35
|
+
return signal?.aborted ? (process.env.DEBUG ? CurlProgressFunc.Continue : 1) : 0;
|
26
36
|
});
|
27
37
|
if (fetchRequest['bodyType'] === 'String') {
|
28
38
|
curlHandle.setOpt('POSTFIELDS', fetchRequest['bodyInit']);
|
@@ -69,9 +79,7 @@ function fetchCurl(fetchRequest) {
|
|
69
79
|
}
|
70
80
|
}
|
71
81
|
}
|
72
|
-
|
73
|
-
fetchRequest.signal.addEventListener('abort', onAbort, { once: true });
|
74
|
-
}
|
82
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
75
83
|
curlHandle.once('end', function endListener() {
|
76
84
|
try {
|
77
85
|
curlHandle.close();
|
@@ -79,9 +87,7 @@ function fetchCurl(fetchRequest) {
|
|
79
87
|
catch (e) {
|
80
88
|
deferredPromise.reject(e);
|
81
89
|
}
|
82
|
-
|
83
|
-
fetchRequest.signal.removeEventListener('abort', onAbort);
|
84
|
-
}
|
90
|
+
signal?.removeEventListener('abort', onAbort);
|
85
91
|
});
|
86
92
|
curlHandle.once('error', function errorListener(error) {
|
87
93
|
if (streamResolved && !streamResolved.closed && !streamResolved.destroyed) {
|
@@ -103,7 +109,7 @@ function fetchCurl(fetchRequest) {
|
|
103
109
|
curlHandle.once('stream', function streamListener(stream, status, headersBuf) {
|
104
110
|
const outputStream = (0, utils_js_1.wrapIncomingMessageWithPassthrough)({
|
105
111
|
incomingMessage: stream,
|
106
|
-
signal
|
112
|
+
signal,
|
107
113
|
onError: deferredPromise.reject,
|
108
114
|
});
|
109
115
|
const headersFlat = headersBuf
|
package/cjs/fetchNodeHttp.js
CHANGED
@@ -28,13 +28,23 @@ function fetchNodeHttp(fetchRequest) {
|
|
28
28
|
if (nodeHeaders['accept-encoding'] == null) {
|
29
29
|
nodeHeaders['accept-encoding'] = 'gzip, deflate, br';
|
30
30
|
}
|
31
|
+
let signal;
|
32
|
+
if (fetchRequest._signal === null) {
|
33
|
+
signal = undefined;
|
34
|
+
}
|
35
|
+
else if (fetchRequest._signal) {
|
36
|
+
signal = fetchRequest._signal;
|
37
|
+
}
|
38
|
+
else {
|
39
|
+
signal = fetchRequest.signal;
|
40
|
+
}
|
31
41
|
let nodeRequest;
|
32
42
|
// If it is our ponyfilled Request, it should have `parsedUrl` which is a `URL` object
|
33
43
|
if (fetchRequest.parsedUrl) {
|
34
44
|
nodeRequest = requestFn(fetchRequest.parsedUrl, {
|
35
45
|
method: fetchRequest.method,
|
36
46
|
headers: nodeHeaders,
|
37
|
-
signal
|
47
|
+
signal,
|
38
48
|
agent: fetchRequest.agent,
|
39
49
|
});
|
40
50
|
}
|
@@ -42,7 +52,7 @@ function fetchNodeHttp(fetchRequest) {
|
|
42
52
|
nodeRequest = requestFn(fetchRequest.url, {
|
43
53
|
method: fetchRequest.method,
|
44
54
|
headers: nodeHeaders,
|
45
|
-
signal
|
55
|
+
signal,
|
46
56
|
agent: fetchRequest.agent,
|
47
57
|
});
|
48
58
|
}
|
@@ -89,7 +99,7 @@ function fetchNodeHttp(fetchRequest) {
|
|
89
99
|
outputStream = (0, utils_js_1.wrapIncomingMessageWithPassthrough)({
|
90
100
|
incomingMessage: nodeResponse,
|
91
101
|
passThrough: outputStream,
|
92
|
-
signal
|
102
|
+
signal,
|
93
103
|
onError: reject,
|
94
104
|
});
|
95
105
|
}
|
@@ -103,12 +113,12 @@ function fetchNodeHttp(fetchRequest) {
|
|
103
113
|
statusText,
|
104
114
|
headers: nodeResponse.headers,
|
105
115
|
url: fetchRequest.url,
|
106
|
-
signal
|
116
|
+
signal,
|
107
117
|
});
|
108
118
|
resolve(ponyfillResponse);
|
109
119
|
});
|
110
120
|
if (fetchRequest['_buffer'] != null) {
|
111
|
-
(0, promise_helpers_1.handleMaybePromise)(() => (0, utils_js_1.safeWrite)(fetchRequest['_buffer'], nodeRequest,
|
121
|
+
(0, promise_helpers_1.handleMaybePromise)(() => (0, utils_js_1.safeWrite)(fetchRequest['_buffer'], nodeRequest, signal), () => (0, utils_js_1.endStream)(nodeRequest), reject);
|
112
122
|
}
|
113
123
|
else {
|
114
124
|
const nodeReadable = (fetchRequest.body != null
|
package/esm/Body.js
CHANGED
@@ -25,11 +25,11 @@ export class PonyfillBody {
|
|
25
25
|
bodyUsed = false;
|
26
26
|
contentType = null;
|
27
27
|
contentLength = null;
|
28
|
-
|
28
|
+
_signal = null;
|
29
29
|
constructor(bodyInit, options = {}) {
|
30
30
|
this.bodyInit = bodyInit;
|
31
31
|
this.options = options;
|
32
|
-
this.
|
32
|
+
this._signal = options.signal || null;
|
33
33
|
const { bodyFactory, contentType, contentLength, bodyType, buffer } = processBodyInit(bodyInit, options?.signal);
|
34
34
|
this._bodyFactory = bodyFactory;
|
35
35
|
this.contentType = contentType;
|
@@ -202,8 +202,8 @@ export class PonyfillBody {
|
|
202
202
|
limits: formDataLimits,
|
203
203
|
defCharset: 'utf-8',
|
204
204
|
});
|
205
|
-
if (this.
|
206
|
-
addAbortSignal(this.
|
205
|
+
if (this._signal) {
|
206
|
+
addAbortSignal(this._signal, bb);
|
207
207
|
}
|
208
208
|
let completed = false;
|
209
209
|
const complete = (err) => {
|
package/esm/Request.js
CHANGED
@@ -54,7 +54,6 @@ export class PonyfillRequest extends PonyfillBody {
|
|
54
54
|
this.redirect = requestInit?.redirect || 'follow';
|
55
55
|
this.referrer = requestInit?.referrer || 'about:client';
|
56
56
|
this.referrerPolicy = requestInit?.referrerPolicy || 'no-referrer';
|
57
|
-
this.signal = requestInit?.signal || new AbortController().signal;
|
58
57
|
this.headersSerializer = requestInit?.headersSerializer;
|
59
58
|
this.duplex = requestInit?.duplex || 'half';
|
60
59
|
this.destination = 'document';
|
@@ -89,6 +88,10 @@ export class PonyfillRequest extends PonyfillBody {
|
|
89
88
|
referrer;
|
90
89
|
referrerPolicy;
|
91
90
|
_url;
|
91
|
+
get signal() {
|
92
|
+
this._signal ||= new AbortController().signal;
|
93
|
+
return this._signal;
|
94
|
+
}
|
92
95
|
get url() {
|
93
96
|
if (this._url == null) {
|
94
97
|
if (this._parsedUrl) {
|
@@ -114,7 +117,6 @@ export class PonyfillRequest extends PonyfillBody {
|
|
114
117
|
}
|
115
118
|
duplex;
|
116
119
|
agent;
|
117
|
-
signal;
|
118
120
|
clone() {
|
119
121
|
return this;
|
120
122
|
}
|
package/esm/Response.js
CHANGED
@@ -15,7 +15,6 @@ export class PonyfillResponse extends PonyfillBody {
|
|
15
15
|
this.url = init?.url || '';
|
16
16
|
this.redirected = init?.redirected || false;
|
17
17
|
this.type = init?.type || 'default';
|
18
|
-
this.signal = init?.signal || null;
|
19
18
|
this.handleContentLengthHeader();
|
20
19
|
}
|
21
20
|
get ok() {
|
package/esm/fetchCurl.js
CHANGED
@@ -18,8 +18,18 @@ export function fetchCurl(fetchRequest) {
|
|
18
18
|
curlHandle.setOpt('CAINFO_BLOB', rootCertificates.join('\n'));
|
19
19
|
}
|
20
20
|
curlHandle.enable(CurlFeature.StreamResponse);
|
21
|
+
let signal;
|
22
|
+
if (fetchRequest._signal === null) {
|
23
|
+
signal = undefined;
|
24
|
+
}
|
25
|
+
else if (fetchRequest._signal) {
|
26
|
+
signal = fetchRequest._signal;
|
27
|
+
}
|
28
|
+
else {
|
29
|
+
signal = fetchRequest.signal;
|
30
|
+
}
|
21
31
|
curlHandle.setStreamProgressCallback(function () {
|
22
|
-
return
|
32
|
+
return signal?.aborted ? (process.env.DEBUG ? CurlProgressFunc.Continue : 1) : 0;
|
23
33
|
});
|
24
34
|
if (fetchRequest['bodyType'] === 'String') {
|
25
35
|
curlHandle.setOpt('POSTFIELDS', fetchRequest['bodyInit']);
|
@@ -66,9 +76,7 @@ export function fetchCurl(fetchRequest) {
|
|
66
76
|
}
|
67
77
|
}
|
68
78
|
}
|
69
|
-
|
70
|
-
fetchRequest.signal.addEventListener('abort', onAbort, { once: true });
|
71
|
-
}
|
79
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
72
80
|
curlHandle.once('end', function endListener() {
|
73
81
|
try {
|
74
82
|
curlHandle.close();
|
@@ -76,9 +84,7 @@ export function fetchCurl(fetchRequest) {
|
|
76
84
|
catch (e) {
|
77
85
|
deferredPromise.reject(e);
|
78
86
|
}
|
79
|
-
|
80
|
-
fetchRequest.signal.removeEventListener('abort', onAbort);
|
81
|
-
}
|
87
|
+
signal?.removeEventListener('abort', onAbort);
|
82
88
|
});
|
83
89
|
curlHandle.once('error', function errorListener(error) {
|
84
90
|
if (streamResolved && !streamResolved.closed && !streamResolved.destroyed) {
|
@@ -100,7 +106,7 @@ export function fetchCurl(fetchRequest) {
|
|
100
106
|
curlHandle.once('stream', function streamListener(stream, status, headersBuf) {
|
101
107
|
const outputStream = wrapIncomingMessageWithPassthrough({
|
102
108
|
incomingMessage: stream,
|
103
|
-
signal
|
109
|
+
signal,
|
104
110
|
onError: deferredPromise.reject,
|
105
111
|
});
|
106
112
|
const headersFlat = headersBuf
|
package/esm/fetchNodeHttp.js
CHANGED
@@ -25,13 +25,23 @@ export function fetchNodeHttp(fetchRequest) {
|
|
25
25
|
if (nodeHeaders['accept-encoding'] == null) {
|
26
26
|
nodeHeaders['accept-encoding'] = 'gzip, deflate, br';
|
27
27
|
}
|
28
|
+
let signal;
|
29
|
+
if (fetchRequest._signal === null) {
|
30
|
+
signal = undefined;
|
31
|
+
}
|
32
|
+
else if (fetchRequest._signal) {
|
33
|
+
signal = fetchRequest._signal;
|
34
|
+
}
|
35
|
+
else {
|
36
|
+
signal = fetchRequest.signal;
|
37
|
+
}
|
28
38
|
let nodeRequest;
|
29
39
|
// If it is our ponyfilled Request, it should have `parsedUrl` which is a `URL` object
|
30
40
|
if (fetchRequest.parsedUrl) {
|
31
41
|
nodeRequest = requestFn(fetchRequest.parsedUrl, {
|
32
42
|
method: fetchRequest.method,
|
33
43
|
headers: nodeHeaders,
|
34
|
-
signal
|
44
|
+
signal,
|
35
45
|
agent: fetchRequest.agent,
|
36
46
|
});
|
37
47
|
}
|
@@ -39,7 +49,7 @@ export function fetchNodeHttp(fetchRequest) {
|
|
39
49
|
nodeRequest = requestFn(fetchRequest.url, {
|
40
50
|
method: fetchRequest.method,
|
41
51
|
headers: nodeHeaders,
|
42
|
-
signal
|
52
|
+
signal,
|
43
53
|
agent: fetchRequest.agent,
|
44
54
|
});
|
45
55
|
}
|
@@ -86,7 +96,7 @@ export function fetchNodeHttp(fetchRequest) {
|
|
86
96
|
outputStream = wrapIncomingMessageWithPassthrough({
|
87
97
|
incomingMessage: nodeResponse,
|
88
98
|
passThrough: outputStream,
|
89
|
-
signal
|
99
|
+
signal,
|
90
100
|
onError: reject,
|
91
101
|
});
|
92
102
|
}
|
@@ -100,12 +110,12 @@ export function fetchNodeHttp(fetchRequest) {
|
|
100
110
|
statusText,
|
101
111
|
headers: nodeResponse.headers,
|
102
112
|
url: fetchRequest.url,
|
103
|
-
signal
|
113
|
+
signal,
|
104
114
|
});
|
105
115
|
resolve(ponyfillResponse);
|
106
116
|
});
|
107
117
|
if (fetchRequest['_buffer'] != null) {
|
108
|
-
handleMaybePromise(() => safeWrite(fetchRequest['_buffer'], nodeRequest,
|
118
|
+
handleMaybePromise(() => safeWrite(fetchRequest['_buffer'], nodeRequest, signal), () => endStream(nodeRequest), reject);
|
109
119
|
}
|
110
120
|
else {
|
111
121
|
const nodeReadable = (fetchRequest.body != null
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@whatwg-node/node-fetch",
|
3
|
-
"version": "0.7.20-alpha-
|
3
|
+
"version": "0.7.20-alpha-20250513235048-f0d1b73cf44dc6870290e4a0cbd4b996a4225a62",
|
4
4
|
"description": "Fetch API implementation for Node",
|
5
5
|
"sideEffects": false,
|
6
6
|
"dependencies": {
|
package/typings/Body.d.cts
CHANGED
@@ -16,7 +16,7 @@ export interface FormDataLimits {
|
|
16
16
|
}
|
17
17
|
export interface PonyfillBodyOptions {
|
18
18
|
formDataLimits?: FormDataLimits;
|
19
|
-
signal?: AbortSignal;
|
19
|
+
signal?: AbortSignal | undefined;
|
20
20
|
}
|
21
21
|
export declare class PonyfillBody<TJSON = any> implements Body {
|
22
22
|
private bodyInit;
|
@@ -24,7 +24,7 @@ export declare class PonyfillBody<TJSON = any> implements Body {
|
|
24
24
|
bodyUsed: boolean;
|
25
25
|
contentType: string | null;
|
26
26
|
contentLength: number | null;
|
27
|
-
|
27
|
+
_signal?: AbortSignal | null;
|
28
28
|
constructor(bodyInit: BodyPonyfillInit | null, options?: PonyfillBodyOptions);
|
29
29
|
private bodyType?;
|
30
30
|
private _bodyFactory;
|
package/typings/Body.d.ts
CHANGED
@@ -16,7 +16,7 @@ export interface FormDataLimits {
|
|
16
16
|
}
|
17
17
|
export interface PonyfillBodyOptions {
|
18
18
|
formDataLimits?: FormDataLimits;
|
19
|
-
signal?: AbortSignal;
|
19
|
+
signal?: AbortSignal | undefined;
|
20
20
|
}
|
21
21
|
export declare class PonyfillBody<TJSON = any> implements Body {
|
22
22
|
private bodyInit;
|
@@ -24,7 +24,7 @@ export declare class PonyfillBody<TJSON = any> implements Body {
|
|
24
24
|
bodyUsed: boolean;
|
25
25
|
contentType: string | null;
|
26
26
|
contentLength: number | null;
|
27
|
-
|
27
|
+
_signal?: AbortSignal | null;
|
28
28
|
constructor(bodyInit: BodyPonyfillInit | null, options?: PonyfillBodyOptions);
|
29
29
|
private bodyType?;
|
30
30
|
private _bodyFactory;
|
package/typings/Request.d.cts
CHANGED
@@ -26,12 +26,12 @@ export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> im
|
|
26
26
|
referrer: string;
|
27
27
|
referrerPolicy: ReferrerPolicy;
|
28
28
|
_url: string | undefined;
|
29
|
+
get signal(): AbortSignal;
|
29
30
|
get url(): string;
|
30
31
|
_parsedUrl: URL | undefined;
|
31
32
|
get parsedUrl(): URL;
|
32
33
|
duplex: 'half' | 'full';
|
33
34
|
agent: HTTPAgent | HTTPSAgent | false | undefined;
|
34
|
-
signal: AbortSignal;
|
35
35
|
clone(): PonyfillRequest<TJSON>;
|
36
36
|
[Symbol.toStringTag]: string;
|
37
37
|
}
|
package/typings/Request.d.ts
CHANGED
@@ -26,12 +26,12 @@ export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> im
|
|
26
26
|
referrer: string;
|
27
27
|
referrerPolicy: ReferrerPolicy;
|
28
28
|
_url: string | undefined;
|
29
|
+
get signal(): AbortSignal;
|
29
30
|
get url(): string;
|
30
31
|
_parsedUrl: URL | undefined;
|
31
32
|
get parsedUrl(): URL;
|
32
33
|
duplex: 'half' | 'full';
|
33
34
|
agent: HTTPAgent | HTTPSAgent | false | undefined;
|
34
|
-
signal: AbortSignal;
|
35
35
|
clone(): PonyfillRequest<TJSON>;
|
36
36
|
[Symbol.toStringTag]: string;
|
37
37
|
}
|