@whatwg-node/node-fetch 0.7.20-alpha-20250513235048-f0d1b73cf44dc6870290e4a0cbd4b996a4225a62 → 0.7.20-alpha-20250514143118-861bcaf9d29ff307a618dbf84bce9a4397706be4
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 +2 -4
- package/cjs/Response.js +1 -0
- package/cjs/fetchCurl.js +8 -14
- package/cjs/fetchNodeHttp.js +5 -15
- package/esm/Body.js +4 -4
- package/esm/Request.js +2 -4
- package/esm/Response.js +1 -0
- package/esm/fetchCurl.js +8 -14
- package/esm/fetchNodeHttp.js +5 -15
- 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,6 +57,7 @@ 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;
|
60
61
|
this.headersSerializer = requestInit?.headersSerializer;
|
61
62
|
this.duplex = requestInit?.duplex || 'half';
|
62
63
|
this.destination = 'document';
|
@@ -91,10 +92,6 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
|
|
91
92
|
referrer;
|
92
93
|
referrerPolicy;
|
93
94
|
_url;
|
94
|
-
get signal() {
|
95
|
-
this._signal ||= new AbortController().signal;
|
96
|
-
return this._signal;
|
97
|
-
}
|
98
95
|
get url() {
|
99
96
|
if (this._url == null) {
|
100
97
|
if (this._parsedUrl) {
|
@@ -120,6 +117,7 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
|
|
120
117
|
}
|
121
118
|
duplex;
|
122
119
|
agent;
|
120
|
+
signal;
|
123
121
|
clone() {
|
124
122
|
return this;
|
125
123
|
}
|
package/cjs/Response.js
CHANGED
@@ -18,6 +18,7 @@ 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;
|
21
22
|
this.handleContentLengthHeader();
|
22
23
|
}
|
23
24
|
get ok() {
|
package/cjs/fetchCurl.js
CHANGED
@@ -21,18 +21,8 @@ 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
|
-
}
|
34
24
|
curlHandle.setStreamProgressCallback(function () {
|
35
|
-
return signal
|
25
|
+
return fetchRequest.signal.aborted ? (process.env.DEBUG ? CurlProgressFunc.Continue : 1) : 0;
|
36
26
|
});
|
37
27
|
if (fetchRequest['bodyType'] === 'String') {
|
38
28
|
curlHandle.setOpt('POSTFIELDS', fetchRequest['bodyInit']);
|
@@ -79,7 +69,9 @@ function fetchCurl(fetchRequest) {
|
|
79
69
|
}
|
80
70
|
}
|
81
71
|
}
|
82
|
-
signal
|
72
|
+
if (fetchRequest.signal) {
|
73
|
+
fetchRequest.signal.addEventListener('abort', onAbort, { once: true });
|
74
|
+
}
|
83
75
|
curlHandle.once('end', function endListener() {
|
84
76
|
try {
|
85
77
|
curlHandle.close();
|
@@ -87,7 +79,9 @@ function fetchCurl(fetchRequest) {
|
|
87
79
|
catch (e) {
|
88
80
|
deferredPromise.reject(e);
|
89
81
|
}
|
90
|
-
signal
|
82
|
+
if (fetchRequest.signal) {
|
83
|
+
fetchRequest.signal.removeEventListener('abort', onAbort);
|
84
|
+
}
|
91
85
|
});
|
92
86
|
curlHandle.once('error', function errorListener(error) {
|
93
87
|
if (streamResolved && !streamResolved.closed && !streamResolved.destroyed) {
|
@@ -109,7 +103,7 @@ function fetchCurl(fetchRequest) {
|
|
109
103
|
curlHandle.once('stream', function streamListener(stream, status, headersBuf) {
|
110
104
|
const outputStream = (0, utils_js_1.wrapIncomingMessageWithPassthrough)({
|
111
105
|
incomingMessage: stream,
|
112
|
-
signal,
|
106
|
+
signal: fetchRequest.signal,
|
113
107
|
onError: deferredPromise.reject,
|
114
108
|
});
|
115
109
|
const headersFlat = headersBuf
|
package/cjs/fetchNodeHttp.js
CHANGED
@@ -28,23 +28,13 @@ 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
|
-
}
|
41
31
|
let nodeRequest;
|
42
32
|
// If it is our ponyfilled Request, it should have `parsedUrl` which is a `URL` object
|
43
33
|
if (fetchRequest.parsedUrl) {
|
44
34
|
nodeRequest = requestFn(fetchRequest.parsedUrl, {
|
45
35
|
method: fetchRequest.method,
|
46
36
|
headers: nodeHeaders,
|
47
|
-
signal,
|
37
|
+
signal: fetchRequest.signal,
|
48
38
|
agent: fetchRequest.agent,
|
49
39
|
});
|
50
40
|
}
|
@@ -52,7 +42,7 @@ function fetchNodeHttp(fetchRequest) {
|
|
52
42
|
nodeRequest = requestFn(fetchRequest.url, {
|
53
43
|
method: fetchRequest.method,
|
54
44
|
headers: nodeHeaders,
|
55
|
-
signal,
|
45
|
+
signal: fetchRequest.signal,
|
56
46
|
agent: fetchRequest.agent,
|
57
47
|
});
|
58
48
|
}
|
@@ -99,7 +89,7 @@ function fetchNodeHttp(fetchRequest) {
|
|
99
89
|
outputStream = (0, utils_js_1.wrapIncomingMessageWithPassthrough)({
|
100
90
|
incomingMessage: nodeResponse,
|
101
91
|
passThrough: outputStream,
|
102
|
-
signal,
|
92
|
+
signal: fetchRequest.signal,
|
103
93
|
onError: reject,
|
104
94
|
});
|
105
95
|
}
|
@@ -113,12 +103,12 @@ function fetchNodeHttp(fetchRequest) {
|
|
113
103
|
statusText,
|
114
104
|
headers: nodeResponse.headers,
|
115
105
|
url: fetchRequest.url,
|
116
|
-
signal,
|
106
|
+
signal: fetchRequest.signal,
|
117
107
|
});
|
118
108
|
resolve(ponyfillResponse);
|
119
109
|
});
|
120
110
|
if (fetchRequest['_buffer'] != null) {
|
121
|
-
(0, promise_helpers_1.handleMaybePromise)(() => (0, utils_js_1.safeWrite)(fetchRequest['_buffer'], nodeRequest, signal), () => (0, utils_js_1.endStream)(nodeRequest), reject);
|
111
|
+
(0, promise_helpers_1.handleMaybePromise)(() => (0, utils_js_1.safeWrite)(fetchRequest['_buffer'], nodeRequest, fetchRequest.signal), () => (0, utils_js_1.endStream)(nodeRequest), reject);
|
122
112
|
}
|
123
113
|
else {
|
124
114
|
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,6 +54,7 @@ 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;
|
57
58
|
this.headersSerializer = requestInit?.headersSerializer;
|
58
59
|
this.duplex = requestInit?.duplex || 'half';
|
59
60
|
this.destination = 'document';
|
@@ -88,10 +89,6 @@ export class PonyfillRequest extends PonyfillBody {
|
|
88
89
|
referrer;
|
89
90
|
referrerPolicy;
|
90
91
|
_url;
|
91
|
-
get signal() {
|
92
|
-
this._signal ||= new AbortController().signal;
|
93
|
-
return this._signal;
|
94
|
-
}
|
95
92
|
get url() {
|
96
93
|
if (this._url == null) {
|
97
94
|
if (this._parsedUrl) {
|
@@ -117,6 +114,7 @@ export class PonyfillRequest extends PonyfillBody {
|
|
117
114
|
}
|
118
115
|
duplex;
|
119
116
|
agent;
|
117
|
+
signal;
|
120
118
|
clone() {
|
121
119
|
return this;
|
122
120
|
}
|
package/esm/Response.js
CHANGED
@@ -15,6 +15,7 @@ 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;
|
18
19
|
this.handleContentLengthHeader();
|
19
20
|
}
|
20
21
|
get ok() {
|
package/esm/fetchCurl.js
CHANGED
@@ -18,18 +18,8 @@ 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
|
-
}
|
31
21
|
curlHandle.setStreamProgressCallback(function () {
|
32
|
-
return signal
|
22
|
+
return fetchRequest.signal.aborted ? (process.env.DEBUG ? CurlProgressFunc.Continue : 1) : 0;
|
33
23
|
});
|
34
24
|
if (fetchRequest['bodyType'] === 'String') {
|
35
25
|
curlHandle.setOpt('POSTFIELDS', fetchRequest['bodyInit']);
|
@@ -76,7 +66,9 @@ export function fetchCurl(fetchRequest) {
|
|
76
66
|
}
|
77
67
|
}
|
78
68
|
}
|
79
|
-
signal
|
69
|
+
if (fetchRequest.signal) {
|
70
|
+
fetchRequest.signal.addEventListener('abort', onAbort, { once: true });
|
71
|
+
}
|
80
72
|
curlHandle.once('end', function endListener() {
|
81
73
|
try {
|
82
74
|
curlHandle.close();
|
@@ -84,7 +76,9 @@ export function fetchCurl(fetchRequest) {
|
|
84
76
|
catch (e) {
|
85
77
|
deferredPromise.reject(e);
|
86
78
|
}
|
87
|
-
signal
|
79
|
+
if (fetchRequest.signal) {
|
80
|
+
fetchRequest.signal.removeEventListener('abort', onAbort);
|
81
|
+
}
|
88
82
|
});
|
89
83
|
curlHandle.once('error', function errorListener(error) {
|
90
84
|
if (streamResolved && !streamResolved.closed && !streamResolved.destroyed) {
|
@@ -106,7 +100,7 @@ export function fetchCurl(fetchRequest) {
|
|
106
100
|
curlHandle.once('stream', function streamListener(stream, status, headersBuf) {
|
107
101
|
const outputStream = wrapIncomingMessageWithPassthrough({
|
108
102
|
incomingMessage: stream,
|
109
|
-
signal,
|
103
|
+
signal: fetchRequest.signal,
|
110
104
|
onError: deferredPromise.reject,
|
111
105
|
});
|
112
106
|
const headersFlat = headersBuf
|
package/esm/fetchNodeHttp.js
CHANGED
@@ -25,23 +25,13 @@ 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
|
-
}
|
38
28
|
let nodeRequest;
|
39
29
|
// If it is our ponyfilled Request, it should have `parsedUrl` which is a `URL` object
|
40
30
|
if (fetchRequest.parsedUrl) {
|
41
31
|
nodeRequest = requestFn(fetchRequest.parsedUrl, {
|
42
32
|
method: fetchRequest.method,
|
43
33
|
headers: nodeHeaders,
|
44
|
-
signal,
|
34
|
+
signal: fetchRequest.signal,
|
45
35
|
agent: fetchRequest.agent,
|
46
36
|
});
|
47
37
|
}
|
@@ -49,7 +39,7 @@ export function fetchNodeHttp(fetchRequest) {
|
|
49
39
|
nodeRequest = requestFn(fetchRequest.url, {
|
50
40
|
method: fetchRequest.method,
|
51
41
|
headers: nodeHeaders,
|
52
|
-
signal,
|
42
|
+
signal: fetchRequest.signal,
|
53
43
|
agent: fetchRequest.agent,
|
54
44
|
});
|
55
45
|
}
|
@@ -96,7 +86,7 @@ export function fetchNodeHttp(fetchRequest) {
|
|
96
86
|
outputStream = wrapIncomingMessageWithPassthrough({
|
97
87
|
incomingMessage: nodeResponse,
|
98
88
|
passThrough: outputStream,
|
99
|
-
signal,
|
89
|
+
signal: fetchRequest.signal,
|
100
90
|
onError: reject,
|
101
91
|
});
|
102
92
|
}
|
@@ -110,12 +100,12 @@ export function fetchNodeHttp(fetchRequest) {
|
|
110
100
|
statusText,
|
111
101
|
headers: nodeResponse.headers,
|
112
102
|
url: fetchRequest.url,
|
113
|
-
signal,
|
103
|
+
signal: fetchRequest.signal,
|
114
104
|
});
|
115
105
|
resolve(ponyfillResponse);
|
116
106
|
});
|
117
107
|
if (fetchRequest['_buffer'] != null) {
|
118
|
-
handleMaybePromise(() => safeWrite(fetchRequest['_buffer'], nodeRequest, signal), () => endStream(nodeRequest), reject);
|
108
|
+
handleMaybePromise(() => safeWrite(fetchRequest['_buffer'], nodeRequest, fetchRequest.signal), () => endStream(nodeRequest), reject);
|
119
109
|
}
|
120
110
|
else {
|
121
111
|
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-20250514143118-861bcaf9d29ff307a618dbf84bce9a4397706be4",
|
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;
|
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;
|
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;
|
30
29
|
get url(): string;
|
31
30
|
_parsedUrl: URL | undefined;
|
32
31
|
get parsedUrl(): URL;
|
33
32
|
duplex: 'half' | 'full';
|
34
33
|
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;
|
30
29
|
get url(): string;
|
31
30
|
_parsedUrl: URL | undefined;
|
32
31
|
get parsedUrl(): URL;
|
33
32
|
duplex: 'half' | 'full';
|
34
33
|
agent: HTTPAgent | HTTPSAgent | false | undefined;
|
34
|
+
signal: AbortSignal;
|
35
35
|
clone(): PonyfillRequest<TJSON>;
|
36
36
|
[Symbol.toStringTag]: string;
|
37
37
|
}
|