@whatwg-node/node-fetch 0.7.20-alpha-20250516144536-d877ab7207b10d1c763b885206f8767feb838e5a → 0.7.20
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 +8 -24
- package/cjs/Headers.js +2 -23
- package/cjs/Request.js +2 -4
- package/cjs/Response.js +8 -27
- package/cjs/fetchCurl.js +8 -14
- package/cjs/fetchNodeHttp.js +5 -15
- package/cjs/utils.js +0 -5
- package/esm/Body.js +8 -24
- package/esm/Headers.js +2 -23
- package/esm/Request.js +2 -4
- package/esm/Response.js +8 -27
- package/esm/fetchCurl.js +8 -14
- package/esm/fetchNodeHttp.js +5 -15
- package/esm/utils.js +0 -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;
|
@@ -150,13 +150,6 @@ class PonyfillBody {
|
|
150
150
|
if (this._blob) {
|
151
151
|
return (0, utils_js_1.fakePromise)(this._blob);
|
152
152
|
}
|
153
|
-
if (this.bodyType === BodyInitType.String) {
|
154
|
-
this._text = this.bodyInit;
|
155
|
-
this._blob = new Blob_js_1.PonyfillBlob([this._text], {
|
156
|
-
type: this.contentType || 'text/plain;charset=UTF-8',
|
157
|
-
size: this.contentLength,
|
158
|
-
});
|
159
|
-
}
|
160
153
|
if (this.bodyType === BodyInitType.Blob) {
|
161
154
|
this._blob = this.bodyInit;
|
162
155
|
return (0, utils_js_1.fakePromise)(this._blob);
|
@@ -212,8 +205,8 @@ class PonyfillBody {
|
|
212
205
|
limits: formDataLimits,
|
213
206
|
defCharset: 'utf-8',
|
214
207
|
});
|
215
|
-
if (this.
|
216
|
-
(0, node_stream_1.addAbortSignal)(this.
|
208
|
+
if (this.signal) {
|
209
|
+
(0, node_stream_1.addAbortSignal)(this.signal, bb);
|
217
210
|
}
|
218
211
|
let completed = false;
|
219
212
|
const complete = (err) => {
|
@@ -286,17 +279,6 @@ class PonyfillBody {
|
|
286
279
|
if (this._buffer) {
|
287
280
|
return (0, utils_js_1.fakePromise)(this._buffer);
|
288
281
|
}
|
289
|
-
if (this._text) {
|
290
|
-
this._buffer = node_buffer_1.Buffer.from(this._text, 'utf-8');
|
291
|
-
return (0, utils_js_1.fakePromise)(this._buffer);
|
292
|
-
}
|
293
|
-
if (this.bodyType === BodyInitType.String) {
|
294
|
-
return this.text().then(text => {
|
295
|
-
this._text = text;
|
296
|
-
this._buffer = node_buffer_1.Buffer.from(text, 'utf-8');
|
297
|
-
return this._buffer;
|
298
|
-
});
|
299
|
-
}
|
300
282
|
if (this.bodyType === BodyInitType.Blob) {
|
301
283
|
if ((0, Blob_js_1.hasBufferMethod)(this.bodyInit)) {
|
302
284
|
return this.bodyInit.buffer().then(buf => {
|
@@ -376,13 +358,15 @@ function processBodyInit(bodyInit, signal) {
|
|
376
358
|
};
|
377
359
|
}
|
378
360
|
if (typeof bodyInit === 'string') {
|
379
|
-
const
|
361
|
+
const buffer = node_buffer_1.Buffer.from(bodyInit);
|
362
|
+
const contentLength = buffer.byteLength;
|
380
363
|
return {
|
381
364
|
bodyType: BodyInitType.String,
|
382
365
|
contentType: 'text/plain;charset=UTF-8',
|
383
366
|
contentLength,
|
367
|
+
buffer,
|
384
368
|
bodyFactory() {
|
385
|
-
const readable = node_stream_1.Readable.from(
|
369
|
+
const readable = node_stream_1.Readable.from(buffer);
|
386
370
|
return new ReadableStream_js_1.PonyfillReadableStream(readable);
|
387
371
|
},
|
388
372
|
};
|
package/cjs/Headers.js
CHANGED
@@ -66,7 +66,7 @@ class PonyfillHeaders {
|
|
66
66
|
// I could do a getter here, but I'm too lazy to type `getter`.
|
67
67
|
getMap() {
|
68
68
|
if (!this._map) {
|
69
|
-
this._setCookies
|
69
|
+
this._setCookies = [];
|
70
70
|
if (this.headersInit != null) {
|
71
71
|
if (Array.isArray(this.headersInit)) {
|
72
72
|
this._map = new Map();
|
@@ -131,8 +131,7 @@ class PonyfillHeaders {
|
|
131
131
|
return value.toString();
|
132
132
|
}
|
133
133
|
has(name) {
|
134
|
-
|
135
|
-
if (key === 'set-cookie') {
|
134
|
+
if (name === 'set-cookie') {
|
136
135
|
return !!this._setCookies?.length;
|
137
136
|
}
|
138
137
|
return !!this._get(name); // we might need to check if header exists and not just check if it's not nullable
|
@@ -143,26 +142,6 @@ class PonyfillHeaders {
|
|
143
142
|
this._setCookies = [value];
|
144
143
|
return;
|
145
144
|
}
|
146
|
-
if (!this._map && this.headersInit != null) {
|
147
|
-
if (Array.isArray(this.headersInit)) {
|
148
|
-
const found = this.headersInit.find(([headerKey]) => headerKey.toLowerCase() === key);
|
149
|
-
if (found) {
|
150
|
-
found[1] = value;
|
151
|
-
}
|
152
|
-
else {
|
153
|
-
this.headersInit.push([key, value]);
|
154
|
-
}
|
155
|
-
return;
|
156
|
-
}
|
157
|
-
else if (isHeadersLike(this.headersInit)) {
|
158
|
-
this.headersInit.set(key, value);
|
159
|
-
return;
|
160
|
-
}
|
161
|
-
else {
|
162
|
-
this.headersInit[key] = value;
|
163
|
-
return;
|
164
|
-
}
|
165
|
-
}
|
166
145
|
this.getMap().set(key, value);
|
167
146
|
}
|
168
147
|
delete(name) {
|
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() {
|
@@ -48,33 +49,13 @@ class PonyfillResponse extends Body_js_1.PonyfillBody {
|
|
48
49
|
status,
|
49
50
|
});
|
50
51
|
}
|
51
|
-
static json(data, init) {
|
52
|
-
|
53
|
-
init
|
54
|
-
headers
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
}
|
59
|
-
else if (!init.headers) {
|
60
|
-
init.headers = {
|
61
|
-
'content-type': JSON_CONTENT_TYPE,
|
62
|
-
};
|
63
|
-
}
|
64
|
-
else if ((0, Headers_js_1.isHeadersLike)(init.headers)) {
|
65
|
-
if (!init.headers.has('content-type')) {
|
66
|
-
init.headers.set('content-type', JSON_CONTENT_TYPE);
|
67
|
-
}
|
68
|
-
}
|
69
|
-
else if (Array.isArray(init.headers)) {
|
70
|
-
if (!init.headers.some(([key]) => key.toLowerCase() === 'content-type')) {
|
71
|
-
init.headers.push(['content-type', JSON_CONTENT_TYPE]);
|
72
|
-
}
|
73
|
-
}
|
74
|
-
else if (typeof init.headers === 'object') {
|
75
|
-
if (init.headers?.['content-type'] == null) {
|
76
|
-
init.headers['content-type'] = JSON_CONTENT_TYPE;
|
77
|
-
}
|
52
|
+
static json(data, init = {}) {
|
53
|
+
init.headers =
|
54
|
+
init?.headers && (0, Headers_js_1.isHeadersLike)(init.headers)
|
55
|
+
? init.headers
|
56
|
+
: new Headers_js_1.PonyfillHeaders(init?.headers);
|
57
|
+
if (!init.headers.has('content-type')) {
|
58
|
+
init.headers.set('content-type', JSON_CONTENT_TYPE);
|
78
59
|
}
|
79
60
|
return new PonyfillResponse(JSON.stringify(data), init);
|
80
61
|
}
|
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/cjs/utils.js
CHANGED
@@ -20,11 +20,6 @@ function getHeadersObj(headers) {
|
|
20
20
|
if (headers == null || !isHeadersInstance(headers)) {
|
21
21
|
return headers;
|
22
22
|
}
|
23
|
-
// @ts-expect-error - `headersInit` is not a public property
|
24
|
-
if (headers.headersInit && !headers._map && !isHeadersInstance(headers.headersInit)) {
|
25
|
-
// @ts-expect-error - `headersInit` is not a public property
|
26
|
-
return headers.headersInit;
|
27
|
-
}
|
28
23
|
return Object.fromEntries(headers.entries());
|
29
24
|
}
|
30
25
|
function defaultHeadersSerializer(headers, onContentLength) {
|
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;
|
@@ -147,13 +147,6 @@ export class PonyfillBody {
|
|
147
147
|
if (this._blob) {
|
148
148
|
return fakePromise(this._blob);
|
149
149
|
}
|
150
|
-
if (this.bodyType === BodyInitType.String) {
|
151
|
-
this._text = this.bodyInit;
|
152
|
-
this._blob = new PonyfillBlob([this._text], {
|
153
|
-
type: this.contentType || 'text/plain;charset=UTF-8',
|
154
|
-
size: this.contentLength,
|
155
|
-
});
|
156
|
-
}
|
157
150
|
if (this.bodyType === BodyInitType.Blob) {
|
158
151
|
this._blob = this.bodyInit;
|
159
152
|
return fakePromise(this._blob);
|
@@ -209,8 +202,8 @@ export class PonyfillBody {
|
|
209
202
|
limits: formDataLimits,
|
210
203
|
defCharset: 'utf-8',
|
211
204
|
});
|
212
|
-
if (this.
|
213
|
-
addAbortSignal(this.
|
205
|
+
if (this.signal) {
|
206
|
+
addAbortSignal(this.signal, bb);
|
214
207
|
}
|
215
208
|
let completed = false;
|
216
209
|
const complete = (err) => {
|
@@ -283,17 +276,6 @@ export class PonyfillBody {
|
|
283
276
|
if (this._buffer) {
|
284
277
|
return fakePromise(this._buffer);
|
285
278
|
}
|
286
|
-
if (this._text) {
|
287
|
-
this._buffer = Buffer.from(this._text, 'utf-8');
|
288
|
-
return fakePromise(this._buffer);
|
289
|
-
}
|
290
|
-
if (this.bodyType === BodyInitType.String) {
|
291
|
-
return this.text().then(text => {
|
292
|
-
this._text = text;
|
293
|
-
this._buffer = Buffer.from(text, 'utf-8');
|
294
|
-
return this._buffer;
|
295
|
-
});
|
296
|
-
}
|
297
279
|
if (this.bodyType === BodyInitType.Blob) {
|
298
280
|
if (hasBufferMethod(this.bodyInit)) {
|
299
281
|
return this.bodyInit.buffer().then(buf => {
|
@@ -372,13 +354,15 @@ function processBodyInit(bodyInit, signal) {
|
|
372
354
|
};
|
373
355
|
}
|
374
356
|
if (typeof bodyInit === 'string') {
|
375
|
-
const
|
357
|
+
const buffer = Buffer.from(bodyInit);
|
358
|
+
const contentLength = buffer.byteLength;
|
376
359
|
return {
|
377
360
|
bodyType: BodyInitType.String,
|
378
361
|
contentType: 'text/plain;charset=UTF-8',
|
379
362
|
contentLength,
|
363
|
+
buffer,
|
380
364
|
bodyFactory() {
|
381
|
-
const readable = Readable.from(
|
365
|
+
const readable = Readable.from(buffer);
|
382
366
|
return new PonyfillReadableStream(readable);
|
383
367
|
},
|
384
368
|
};
|
package/esm/Headers.js
CHANGED
@@ -62,7 +62,7 @@ export class PonyfillHeaders {
|
|
62
62
|
// I could do a getter here, but I'm too lazy to type `getter`.
|
63
63
|
getMap() {
|
64
64
|
if (!this._map) {
|
65
|
-
this._setCookies
|
65
|
+
this._setCookies = [];
|
66
66
|
if (this.headersInit != null) {
|
67
67
|
if (Array.isArray(this.headersInit)) {
|
68
68
|
this._map = new Map();
|
@@ -127,8 +127,7 @@ export class PonyfillHeaders {
|
|
127
127
|
return value.toString();
|
128
128
|
}
|
129
129
|
has(name) {
|
130
|
-
|
131
|
-
if (key === 'set-cookie') {
|
130
|
+
if (name === 'set-cookie') {
|
132
131
|
return !!this._setCookies?.length;
|
133
132
|
}
|
134
133
|
return !!this._get(name); // we might need to check if header exists and not just check if it's not nullable
|
@@ -139,26 +138,6 @@ export class PonyfillHeaders {
|
|
139
138
|
this._setCookies = [value];
|
140
139
|
return;
|
141
140
|
}
|
142
|
-
if (!this._map && this.headersInit != null) {
|
143
|
-
if (Array.isArray(this.headersInit)) {
|
144
|
-
const found = this.headersInit.find(([headerKey]) => headerKey.toLowerCase() === key);
|
145
|
-
if (found) {
|
146
|
-
found[1] = value;
|
147
|
-
}
|
148
|
-
else {
|
149
|
-
this.headersInit.push([key, value]);
|
150
|
-
}
|
151
|
-
return;
|
152
|
-
}
|
153
|
-
else if (isHeadersLike(this.headersInit)) {
|
154
|
-
this.headersInit.set(key, value);
|
155
|
-
return;
|
156
|
-
}
|
157
|
-
else {
|
158
|
-
this.headersInit[key] = value;
|
159
|
-
return;
|
160
|
-
}
|
161
|
-
}
|
162
141
|
this.getMap().set(key, value);
|
163
142
|
}
|
164
143
|
delete(name) {
|
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() {
|
@@ -45,33 +46,13 @@ export class PonyfillResponse extends PonyfillBody {
|
|
45
46
|
status,
|
46
47
|
});
|
47
48
|
}
|
48
|
-
static json(data, init) {
|
49
|
-
|
50
|
-
init
|
51
|
-
headers
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
}
|
56
|
-
else if (!init.headers) {
|
57
|
-
init.headers = {
|
58
|
-
'content-type': JSON_CONTENT_TYPE,
|
59
|
-
};
|
60
|
-
}
|
61
|
-
else if (isHeadersLike(init.headers)) {
|
62
|
-
if (!init.headers.has('content-type')) {
|
63
|
-
init.headers.set('content-type', JSON_CONTENT_TYPE);
|
64
|
-
}
|
65
|
-
}
|
66
|
-
else if (Array.isArray(init.headers)) {
|
67
|
-
if (!init.headers.some(([key]) => key.toLowerCase() === 'content-type')) {
|
68
|
-
init.headers.push(['content-type', JSON_CONTENT_TYPE]);
|
69
|
-
}
|
70
|
-
}
|
71
|
-
else if (typeof init.headers === 'object') {
|
72
|
-
if (init.headers?.['content-type'] == null) {
|
73
|
-
init.headers['content-type'] = JSON_CONTENT_TYPE;
|
74
|
-
}
|
49
|
+
static json(data, init = {}) {
|
50
|
+
init.headers =
|
51
|
+
init?.headers && isHeadersLike(init.headers)
|
52
|
+
? init.headers
|
53
|
+
: new PonyfillHeaders(init?.headers);
|
54
|
+
if (!init.headers.has('content-type')) {
|
55
|
+
init.headers.set('content-type', JSON_CONTENT_TYPE);
|
75
56
|
}
|
76
57
|
return new PonyfillResponse(JSON.stringify(data), init);
|
77
58
|
}
|
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/esm/utils.js
CHANGED
@@ -8,11 +8,6 @@ export function getHeadersObj(headers) {
|
|
8
8
|
if (headers == null || !isHeadersInstance(headers)) {
|
9
9
|
return headers;
|
10
10
|
}
|
11
|
-
// @ts-expect-error - `headersInit` is not a public property
|
12
|
-
if (headers.headersInit && !headers._map && !isHeadersInstance(headers.headersInit)) {
|
13
|
-
// @ts-expect-error - `headersInit` is not a public property
|
14
|
-
return headers.headersInit;
|
15
|
-
}
|
16
11
|
return Object.fromEntries(headers.entries());
|
17
12
|
}
|
18
13
|
export function defaultHeadersSerializer(headers, onContentLength) {
|
package/package.json
CHANGED
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
|
}
|