rekwest 4.0.0 → 4.2.0
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/README.md +4 -3
- package/dist/ackn.js +1 -1
- package/dist/constants.js +27 -0
- package/dist/cookies.js +1 -1
- package/dist/defaults.js +41 -0
- package/dist/formdata.js +12 -12
- package/dist/index.js +27 -185
- package/dist/postflight.js +110 -0
- package/dist/preflight.js +66 -0
- package/dist/utils.js +138 -95
- package/package.json +3 -3
- package/src/ackn.mjs +1 -1
- package/src/constants.mjs +29 -0
- package/src/cookies.mjs +2 -2
- package/src/defaults.mjs +44 -0
- package/src/formdata.mjs +16 -13
- package/src/index.mjs +84 -282
- package/src/postflight.mjs +135 -0
- package/src/preflight.mjs +70 -0
- package/src/utils.mjs +159 -99
package/dist/utils.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports.sanitize = exports.
|
|
4
|
+
exports.sanitize = exports.sameOrigin = exports.mixin = exports.merge = exports.maxRetryAfterError = exports.maxRetryAfter = exports.dispatch = exports.decompress = exports.compress = exports.brandCheck = exports.affix = exports.admix = void 0;
|
|
5
5
|
exports.tap = tap;
|
|
6
|
-
exports.transform = void 0;
|
|
6
|
+
exports.validation = exports.unwind = exports.transform = exports.transfer = void 0;
|
|
7
7
|
var _nodeBuffer = require("node:buffer");
|
|
8
|
-
var _nodeHttp = _interopRequireDefault(require("node:
|
|
8
|
+
var _nodeHttp = _interopRequireDefault(require("node:http"));
|
|
9
|
+
var _nodeHttp2 = _interopRequireDefault(require("node:http2"));
|
|
10
|
+
var _nodeHttps = _interopRequireDefault(require("node:https"));
|
|
9
11
|
var _nodeStream = require("node:stream");
|
|
10
12
|
var _consumers = require("node:stream/consumers");
|
|
13
|
+
var _promises = require("node:timers/promises");
|
|
11
14
|
var _nodeUtil = require("node:util");
|
|
12
15
|
var _nodeZlib = _interopRequireDefault(require("node:zlib"));
|
|
13
|
-
var
|
|
16
|
+
var _ackn = require("./ackn");
|
|
17
|
+
var _constants = require("./constants");
|
|
14
18
|
var _errors = require("./errors");
|
|
15
19
|
var _file = require("./file");
|
|
16
20
|
var _formdata = require("./formdata");
|
|
21
|
+
var _index = _interopRequireDefault(require("./index"));
|
|
17
22
|
var _mediatypes = require("./mediatypes");
|
|
23
|
+
var _postflight = require("./postflight");
|
|
24
|
+
var _preflight = require("./preflight");
|
|
18
25
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
26
|
const {
|
|
20
|
-
HTTP2_HEADER_ACCEPT,
|
|
21
|
-
HTTP2_HEADER_ACCEPT_ENCODING,
|
|
22
|
-
HTTP2_HEADER_AUTHORITY,
|
|
23
27
|
HTTP2_HEADER_CONTENT_ENCODING,
|
|
24
28
|
HTTP2_HEADER_CONTENT_LENGTH,
|
|
25
29
|
HTTP2_HEADER_CONTENT_TYPE,
|
|
26
|
-
|
|
27
|
-
HTTP2_HEADER_METHOD,
|
|
28
|
-
HTTP2_HEADER_PATH,
|
|
29
|
-
HTTP2_HEADER_SCHEME,
|
|
30
|
+
HTTP2_HEADER_RETRY_AFTER,
|
|
30
31
|
HTTP2_HEADER_STATUS,
|
|
31
32
|
HTTP2_METHOD_GET,
|
|
32
33
|
HTTP2_METHOD_HEAD
|
|
33
|
-
} =
|
|
34
|
-
const unwind = encodings => encodings.split(',').map(it => it.trim());
|
|
34
|
+
} = _nodeHttp2.default.constants;
|
|
35
35
|
const admix = (res, headers, options) => {
|
|
36
36
|
const {
|
|
37
37
|
h2
|
|
@@ -71,12 +71,12 @@ const affix = (client, req, options) => {
|
|
|
71
71
|
});
|
|
72
72
|
};
|
|
73
73
|
exports.affix = affix;
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
74
|
+
const brandCheck = (value, ctor) => {
|
|
75
|
+
if (!(value instanceof ctor)) {
|
|
76
76
|
throw new TypeError('Illegal invocation');
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
|
-
exports.
|
|
79
|
+
exports.brandCheck = brandCheck;
|
|
80
80
|
const compress = (readable, encodings = '') => {
|
|
81
81
|
const encoders = [];
|
|
82
82
|
encodings = unwind(encodings);
|
|
@@ -125,6 +125,10 @@ const dispatch = ({
|
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
127
|
exports.dispatch = dispatch;
|
|
128
|
+
const maxRetryAfter = Symbol('maxRetryAfter');
|
|
129
|
+
exports.maxRetryAfter = maxRetryAfter;
|
|
130
|
+
const maxRetryAfterError = (interval, options) => new _errors.RequestError(`Maximum '${HTTP2_HEADER_RETRY_AFTER}' limit exceeded: ${interval} ms.`, options);
|
|
131
|
+
exports.maxRetryAfterError = maxRetryAfterError;
|
|
128
132
|
const merge = (target = {}, ...rest) => {
|
|
129
133
|
target = JSON.parse(JSON.stringify(target));
|
|
130
134
|
if (!rest.length) {
|
|
@@ -156,7 +160,7 @@ const mixin = (res, {
|
|
|
156
160
|
arrayBuffer: {
|
|
157
161
|
enumerable: true,
|
|
158
162
|
value: async function () {
|
|
159
|
-
|
|
163
|
+
brandCheck(this, res?.constructor);
|
|
160
164
|
parse &&= false;
|
|
161
165
|
const {
|
|
162
166
|
buffer,
|
|
@@ -169,7 +173,7 @@ const mixin = (res, {
|
|
|
169
173
|
blob: {
|
|
170
174
|
enumerable: true,
|
|
171
175
|
value: async function () {
|
|
172
|
-
|
|
176
|
+
brandCheck(this, res?.constructor);
|
|
173
177
|
const val = await this.arrayBuffer();
|
|
174
178
|
return new _nodeBuffer.Blob([val]);
|
|
175
179
|
}
|
|
@@ -177,7 +181,7 @@ const mixin = (res, {
|
|
|
177
181
|
json: {
|
|
178
182
|
enumerable: true,
|
|
179
183
|
value: async function () {
|
|
180
|
-
|
|
184
|
+
brandCheck(this, res?.constructor);
|
|
181
185
|
const val = await this.text();
|
|
182
186
|
return JSON.parse(val);
|
|
183
187
|
}
|
|
@@ -185,7 +189,7 @@ const mixin = (res, {
|
|
|
185
189
|
text: {
|
|
186
190
|
enumerable: true,
|
|
187
191
|
value: async function () {
|
|
188
|
-
|
|
192
|
+
brandCheck(this, res?.constructor);
|
|
189
193
|
const blob = await this.blob();
|
|
190
194
|
return blob.text();
|
|
191
195
|
}
|
|
@@ -196,7 +200,7 @@ const mixin = (res, {
|
|
|
196
200
|
body: {
|
|
197
201
|
enumerable: true,
|
|
198
202
|
value: async function () {
|
|
199
|
-
|
|
203
|
+
brandCheck(this, res?.constructor);
|
|
200
204
|
if (this.bodyUsed) {
|
|
201
205
|
throw new TypeError('Response stream already read');
|
|
202
206
|
}
|
|
@@ -214,7 +218,7 @@ const mixin = (res, {
|
|
|
214
218
|
if (/\bjson\b/i.test(contentType)) {
|
|
215
219
|
body = JSON.parse(body.toString(charset));
|
|
216
220
|
} else if (/\b(?:text|xml)\b/i.test(contentType)) {
|
|
217
|
-
if (/\b(?:latin1|ucs-2|utf-(?:8|16le))\b
|
|
221
|
+
if (/\b(?:latin1|ucs-2|utf-(?:8|16le))\b/i.test(charset)) {
|
|
218
222
|
body = body.toString(charset);
|
|
219
223
|
} else {
|
|
220
224
|
body = new TextDecoder(charset).decode(body);
|
|
@@ -234,72 +238,9 @@ const mixin = (res, {
|
|
|
234
238
|
});
|
|
235
239
|
};
|
|
236
240
|
exports.mixin = mixin;
|
|
237
|
-
const preflight = options => {
|
|
238
|
-
const {
|
|
239
|
-
cookies,
|
|
240
|
-
h2 = false,
|
|
241
|
-
headers,
|
|
242
|
-
method = HTTP2_METHOD_GET,
|
|
243
|
-
redirected,
|
|
244
|
-
url
|
|
245
|
-
} = options;
|
|
246
|
-
if (h2) {
|
|
247
|
-
options.endStream = [HTTP2_METHOD_GET, HTTP2_METHOD_HEAD].includes(method);
|
|
248
|
-
}
|
|
249
|
-
if (cookies !== false) {
|
|
250
|
-
let cookie = _cookies.Cookies.jar.get(url.origin);
|
|
251
|
-
if (cookies === Object(cookies) && !redirected) {
|
|
252
|
-
if (cookie) {
|
|
253
|
-
new _cookies.Cookies(cookies).forEach(function (val, key) {
|
|
254
|
-
this.set(key, val);
|
|
255
|
-
}, cookie);
|
|
256
|
-
} else {
|
|
257
|
-
cookie = new _cookies.Cookies(cookies);
|
|
258
|
-
_cookies.Cookies.jar.set(url.origin, cookie);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
options.headers = {
|
|
262
|
-
...(cookie && {
|
|
263
|
-
[HTTP2_HEADER_COOKIE]: cookie
|
|
264
|
-
}),
|
|
265
|
-
...headers
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
options.digest ??= true;
|
|
269
|
-
options.follow ??= 20;
|
|
270
|
-
options.h2 ??= h2;
|
|
271
|
-
options.headers = {
|
|
272
|
-
[HTTP2_HEADER_ACCEPT]: `${_mediatypes.APPLICATION_JSON}, ${_mediatypes.TEXT_PLAIN}, ${_mediatypes.WILDCARD}`,
|
|
273
|
-
[HTTP2_HEADER_ACCEPT_ENCODING]: 'br, deflate, deflate-raw, gzip, identity',
|
|
274
|
-
...Object.entries(options.headers ?? {}).reduce((acc, [key, val]) => (acc[key.toLowerCase()] = val, acc), {}),
|
|
275
|
-
...(h2 && {
|
|
276
|
-
[HTTP2_HEADER_AUTHORITY]: url.host,
|
|
277
|
-
[HTTP2_HEADER_METHOD]: method,
|
|
278
|
-
[HTTP2_HEADER_PATH]: `${url.pathname}${url.search}`,
|
|
279
|
-
[HTTP2_HEADER_SCHEME]: url.protocol.replace(/\p{Punctuation}/gu, '')
|
|
280
|
-
})
|
|
281
|
-
};
|
|
282
|
-
options.method ??= method;
|
|
283
|
-
options.parse ??= true;
|
|
284
|
-
options.redirect ??= redirects.follow;
|
|
285
|
-
if (!Object.values(redirects).includes(options.redirect)) {
|
|
286
|
-
options.createConnection?.().destroy();
|
|
287
|
-
throw new TypeError(`Failed to read the 'redirect' property from 'options': The provided value '${options.redirect}' is not a valid enum value.`);
|
|
288
|
-
}
|
|
289
|
-
options.redirected ??= false;
|
|
290
|
-
options.thenable ??= false;
|
|
291
|
-
return options;
|
|
292
|
-
};
|
|
293
|
-
exports.preflight = preflight;
|
|
294
|
-
const redirects = {
|
|
295
|
-
error: 'error',
|
|
296
|
-
follow: 'follow',
|
|
297
|
-
manual: 'manual'
|
|
298
|
-
};
|
|
299
|
-
exports.redirects = redirects;
|
|
300
241
|
const sanitize = (url, options = {}) => {
|
|
301
242
|
if (options.trimTrailingSlashes) {
|
|
302
|
-
url = `${url}`.replace(/(?<!:)\/+/
|
|
243
|
+
url = `${url}`.replace(/(?<!:)\/+/g, '/');
|
|
303
244
|
}
|
|
304
245
|
url = new URL(url);
|
|
305
246
|
return Object.assign(options, {
|
|
@@ -307,6 +248,8 @@ const sanitize = (url, options = {}) => {
|
|
|
307
248
|
});
|
|
308
249
|
};
|
|
309
250
|
exports.sanitize = sanitize;
|
|
251
|
+
const sameOrigin = (a, b) => a.protocol === b.protocol && a.hostname === b.hostname && a.port === b.port;
|
|
252
|
+
exports.sameOrigin = sameOrigin;
|
|
310
253
|
async function* tap(value) {
|
|
311
254
|
if (Reflect.has(value, Symbol.asyncIterator)) {
|
|
312
255
|
yield* value;
|
|
@@ -316,6 +259,92 @@ async function* tap(value) {
|
|
|
316
259
|
yield await value.arrayBuffer();
|
|
317
260
|
}
|
|
318
261
|
}
|
|
262
|
+
const transfer = async options => {
|
|
263
|
+
const {
|
|
264
|
+
url
|
|
265
|
+
} = options;
|
|
266
|
+
if (options.follow === 0) {
|
|
267
|
+
throw new _errors.RequestError(`Maximum redirect reached at: ${url.href}`);
|
|
268
|
+
}
|
|
269
|
+
if (url.protocol === 'https:') {
|
|
270
|
+
options = await (0, _ackn.ackn)(options);
|
|
271
|
+
} else if (Reflect.has(options, 'alpnProtocol')) {
|
|
272
|
+
['alpnProtocol', 'createConnection', 'h2', 'protocol'].forEach(it => Reflect.deleteProperty(options, it));
|
|
273
|
+
}
|
|
274
|
+
try {
|
|
275
|
+
options = await transform((0, _preflight.preflight)(options));
|
|
276
|
+
} catch (ex) {
|
|
277
|
+
options.createConnection?.().destroy();
|
|
278
|
+
throw ex;
|
|
279
|
+
}
|
|
280
|
+
const {
|
|
281
|
+
digest,
|
|
282
|
+
h2,
|
|
283
|
+
redirected,
|
|
284
|
+
thenable
|
|
285
|
+
} = options;
|
|
286
|
+
const {
|
|
287
|
+
request
|
|
288
|
+
} = url.protocol === 'http:' ? _nodeHttp.default : _nodeHttps.default;
|
|
289
|
+
const promise = new Promise((resolve, reject) => {
|
|
290
|
+
let client, req;
|
|
291
|
+
if (h2) {
|
|
292
|
+
client = _nodeHttp2.default.connect(url.origin, options);
|
|
293
|
+
req = client.request(options.headers, options);
|
|
294
|
+
} else {
|
|
295
|
+
req = request(url, options);
|
|
296
|
+
}
|
|
297
|
+
affix(client, req, options);
|
|
298
|
+
req.once('error', reject);
|
|
299
|
+
req.once('frameError', reject);
|
|
300
|
+
req.once('goaway', reject);
|
|
301
|
+
req.once('response', res => (0, _postflight.postflight)(req, res, options, {
|
|
302
|
+
reject,
|
|
303
|
+
resolve
|
|
304
|
+
}));
|
|
305
|
+
dispatch(options, req);
|
|
306
|
+
});
|
|
307
|
+
try {
|
|
308
|
+
const res = await promise;
|
|
309
|
+
if (digest && !redirected) {
|
|
310
|
+
res.body = await res.body();
|
|
311
|
+
}
|
|
312
|
+
return res;
|
|
313
|
+
} catch (ex) {
|
|
314
|
+
const {
|
|
315
|
+
maxRetryAfter,
|
|
316
|
+
retry
|
|
317
|
+
} = options;
|
|
318
|
+
if (retry?.attempts && retry?.statusCodes.includes(ex.statusCode)) {
|
|
319
|
+
let {
|
|
320
|
+
interval
|
|
321
|
+
} = retry;
|
|
322
|
+
if (retry.retryAfter && ex.headers[HTTP2_HEADER_RETRY_AFTER]) {
|
|
323
|
+
interval = ex.headers[HTTP2_HEADER_RETRY_AFTER];
|
|
324
|
+
interval = Number(interval) * 1000 || new Date(interval) - Date.now();
|
|
325
|
+
if (interval > maxRetryAfter) {
|
|
326
|
+
throw maxRetryAfterError(interval, {
|
|
327
|
+
cause: ex
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
} else {
|
|
331
|
+
interval = new Function('interval', `return Math.ceil(${retry.backoffStrategy});`)(interval);
|
|
332
|
+
}
|
|
333
|
+
retry.attempts--;
|
|
334
|
+
retry.interval = interval;
|
|
335
|
+
return (0, _promises.setTimeout)(interval).then(() => (0, _index.default)(url, options));
|
|
336
|
+
}
|
|
337
|
+
if (digest && !redirected && ex.body) {
|
|
338
|
+
ex.body = await ex.body();
|
|
339
|
+
}
|
|
340
|
+
if (!thenable) {
|
|
341
|
+
throw ex;
|
|
342
|
+
} else {
|
|
343
|
+
return ex;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
exports.transfer = transfer;
|
|
319
348
|
const transform = async options => {
|
|
320
349
|
let {
|
|
321
350
|
body,
|
|
@@ -355,17 +384,16 @@ const transform = async options => {
|
|
|
355
384
|
}
|
|
356
385
|
}
|
|
357
386
|
const encodings = options.headers[HTTP2_HEADER_CONTENT_ENCODING];
|
|
358
|
-
if (
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
body = await (0, _consumers.buffer)(compress(_nodeStream.Readable.from(body), encodings));
|
|
363
|
-
}
|
|
364
|
-
} else if (body === Object(body) && (Reflect.has(body, Symbol.asyncIterator) || !Array.isArray(body) && Reflect.has(body, Symbol.iterator))) {
|
|
365
|
-
body = _nodeStream.Readable.from(body);
|
|
387
|
+
if (body === Object(body) && (Reflect.has(body, Symbol.asyncIterator) || !Array.isArray(body) && Reflect.has(body, Symbol.iterator))) {
|
|
388
|
+
body = encodings ? compress(_nodeStream.Readable.from(body), encodings) : _nodeStream.Readable.from(body);
|
|
389
|
+
} else if (encodings) {
|
|
390
|
+
body = await (0, _consumers.buffer)(compress(_nodeStream.Readable.from(body), encodings));
|
|
366
391
|
}
|
|
367
392
|
Object.assign(options.headers, {
|
|
368
393
|
...headers,
|
|
394
|
+
...(!body[Symbol.asyncIterator] && {
|
|
395
|
+
[HTTP2_HEADER_CONTENT_LENGTH]: Buffer.byteLength(body)
|
|
396
|
+
}),
|
|
369
397
|
...(options.headers[HTTP2_HEADER_CONTENT_TYPE] && {
|
|
370
398
|
[HTTP2_HEADER_CONTENT_TYPE]: options.headers[HTTP2_HEADER_CONTENT_TYPE]
|
|
371
399
|
})
|
|
@@ -375,4 +403,19 @@ const transform = async options => {
|
|
|
375
403
|
body
|
|
376
404
|
};
|
|
377
405
|
};
|
|
378
|
-
exports.transform = transform;
|
|
406
|
+
exports.transform = transform;
|
|
407
|
+
const unwind = encodings => encodings.split(',').map(it => it.trim());
|
|
408
|
+
exports.unwind = unwind;
|
|
409
|
+
const validation = (options = {}) => {
|
|
410
|
+
if (options.body && [HTTP2_METHOD_GET, HTTP2_METHOD_HEAD].includes(options.method)) {
|
|
411
|
+
throw new TypeError(`Request with ${HTTP2_METHOD_GET}/${HTTP2_METHOD_HEAD} method cannot have body.`);
|
|
412
|
+
}
|
|
413
|
+
if (!Object.values(_constants.requestCredentials).includes(options.credentials)) {
|
|
414
|
+
throw new TypeError(`Failed to read the 'credentials' property from 'options': The provided value '${options.credentials}' is not a valid enum value.`);
|
|
415
|
+
}
|
|
416
|
+
if (!Reflect.has(_constants.requestRedirect, options.redirect)) {
|
|
417
|
+
throw new TypeError(`Failed to read the 'redirect' property from 'options': The provided value '${options.redirect}' is not a valid enum value.`);
|
|
418
|
+
}
|
|
419
|
+
return options;
|
|
420
|
+
};
|
|
421
|
+
exports.validation = validation;
|
package/package.json
CHANGED
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@babel/cli": "^7.19.3",
|
|
12
|
-
"@babel/core": "^7.20.
|
|
12
|
+
"@babel/core": "^7.20.5",
|
|
13
13
|
"@babel/eslint-parser": "^7.19.1",
|
|
14
14
|
"@babel/preset-env": "^7.20.2",
|
|
15
15
|
"c8": "^7.12.0",
|
|
16
|
-
"eslint": "^8.
|
|
16
|
+
"eslint": "^8.28.0",
|
|
17
17
|
"eslint-config-ultra-refined": "^2.10.0",
|
|
18
18
|
"mocha": "^10.1.0"
|
|
19
19
|
},
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"test:bail": "mocha --bail",
|
|
68
68
|
"test:cover": "c8 --include=src --reporter=lcov --reporter=text npm test"
|
|
69
69
|
},
|
|
70
|
-
"version": "4.
|
|
70
|
+
"version": "4.2.0"
|
|
71
71
|
}
|
package/src/ackn.mjs
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import http2 from 'node:http2';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
HTTP_STATUS_FOUND,
|
|
5
|
+
HTTP_STATUS_MOVED_PERMANENTLY,
|
|
6
|
+
HTTP_STATUS_PERMANENT_REDIRECT,
|
|
7
|
+
HTTP_STATUS_SEE_OTHER,
|
|
8
|
+
HTTP_STATUS_TEMPORARY_REDIRECT,
|
|
9
|
+
} = http2.constants;
|
|
10
|
+
|
|
11
|
+
export const requestCredentials = {
|
|
12
|
+
include: 'include',
|
|
13
|
+
omit: 'omit',
|
|
14
|
+
sameOrigin: 'same-origin',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const requestRedirect = {
|
|
18
|
+
error: 'error',
|
|
19
|
+
follow: 'follow',
|
|
20
|
+
manual: 'manual',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const requestRedirectCodes = [
|
|
24
|
+
HTTP_STATUS_MOVED_PERMANENTLY,
|
|
25
|
+
HTTP_STATUS_FOUND,
|
|
26
|
+
HTTP_STATUS_SEE_OTHER,
|
|
27
|
+
HTTP_STATUS_TEMPORARY_REDIRECT,
|
|
28
|
+
HTTP_STATUS_PERMANENT_REDIRECT,
|
|
29
|
+
];
|
package/src/cookies.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { brandCheck } from './utils.mjs';
|
|
2
2
|
|
|
3
3
|
export class Cookies extends URLSearchParams {
|
|
4
4
|
|
|
@@ -20,7 +20,7 @@ export class Cookies extends URLSearchParams {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
toString() {
|
|
23
|
-
|
|
23
|
+
brandCheck(this, Cookies);
|
|
24
24
|
|
|
25
25
|
return super.toString().split('&').join('; ').trim();
|
|
26
26
|
}
|
package/src/defaults.mjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import http2 from 'node:http2';
|
|
2
|
+
import {
|
|
3
|
+
requestCredentials,
|
|
4
|
+
requestRedirect,
|
|
5
|
+
} from './constants.mjs';
|
|
6
|
+
import { maxRetryAfter } from './utils.mjs';
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
HTTP2_METHOD_GET,
|
|
10
|
+
HTTP_STATUS_SERVICE_UNAVAILABLE,
|
|
11
|
+
HTTP_STATUS_TOO_MANY_REQUESTS,
|
|
12
|
+
} = http2.constants;
|
|
13
|
+
|
|
14
|
+
const stash = {
|
|
15
|
+
credentials: requestCredentials.sameOrigin,
|
|
16
|
+
digest: true,
|
|
17
|
+
follow: 20,
|
|
18
|
+
get maxRetryAfter() {
|
|
19
|
+
return this[maxRetryAfter] ?? this.timeout;
|
|
20
|
+
},
|
|
21
|
+
set maxRetryAfter(value) {
|
|
22
|
+
this[maxRetryAfter] = value;
|
|
23
|
+
},
|
|
24
|
+
method: HTTP2_METHOD_GET,
|
|
25
|
+
parse: true,
|
|
26
|
+
redirect: requestRedirect.follow,
|
|
27
|
+
redirected: false,
|
|
28
|
+
retry: {
|
|
29
|
+
attempts: 0,
|
|
30
|
+
backoffStrategy: 'interval * Math.log(Math.random() * (Math.E * Math.E - Math.E) + Math.E)',
|
|
31
|
+
interval: 1e3,
|
|
32
|
+
retryAfter: true,
|
|
33
|
+
statusCodes: [
|
|
34
|
+
HTTP_STATUS_TOO_MANY_REQUESTS,
|
|
35
|
+
HTTP_STATUS_SERVICE_UNAVAILABLE,
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
thenable: false,
|
|
39
|
+
timeout: 3e5,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default {
|
|
43
|
+
stash,
|
|
44
|
+
};
|
package/src/formdata.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
MULTIPART_FORM_DATA,
|
|
8
8
|
} from './mediatypes.mjs';
|
|
9
9
|
import {
|
|
10
|
-
|
|
10
|
+
brandCheck,
|
|
11
11
|
tap,
|
|
12
12
|
} from './utils.mjs';
|
|
13
13
|
|
|
@@ -46,7 +46,10 @@ export class FormData {
|
|
|
46
46
|
value.type || APPLICATION_OCTET_STREAM
|
|
47
47
|
}${ CRLF.repeat(2) }`);
|
|
48
48
|
yield* tap(value);
|
|
49
|
-
yield
|
|
49
|
+
yield new Uint8Array([
|
|
50
|
+
13,
|
|
51
|
+
10,
|
|
52
|
+
]);
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
55
|
|
|
@@ -144,13 +147,13 @@ export class FormData {
|
|
|
144
147
|
}
|
|
145
148
|
|
|
146
149
|
append(...args) {
|
|
147
|
-
|
|
150
|
+
brandCheck(this, FormData);
|
|
148
151
|
this.#ensureArgs(args, 2, 'append');
|
|
149
152
|
this.#entries.push(this.constructor.#enfoldEntry(...args));
|
|
150
153
|
}
|
|
151
154
|
|
|
152
155
|
delete(...args) {
|
|
153
|
-
|
|
156
|
+
brandCheck(this, FormData);
|
|
154
157
|
this.#ensureArgs(args, 1, 'delete');
|
|
155
158
|
const name = toUSVString(args[0]);
|
|
156
159
|
|
|
@@ -158,7 +161,7 @@ export class FormData {
|
|
|
158
161
|
}
|
|
159
162
|
|
|
160
163
|
forEach(...args) {
|
|
161
|
-
|
|
164
|
+
brandCheck(this, FormData);
|
|
162
165
|
this.#ensureArgs(args, 1, 'forEach');
|
|
163
166
|
const [callback, thisArg] = args;
|
|
164
167
|
|
|
@@ -171,7 +174,7 @@ export class FormData {
|
|
|
171
174
|
}
|
|
172
175
|
|
|
173
176
|
get(...args) {
|
|
174
|
-
|
|
177
|
+
brandCheck(this, FormData);
|
|
175
178
|
this.#ensureArgs(args, 1, 'get');
|
|
176
179
|
const name = toUSVString(args[0]);
|
|
177
180
|
|
|
@@ -179,7 +182,7 @@ export class FormData {
|
|
|
179
182
|
}
|
|
180
183
|
|
|
181
184
|
getAll(...args) {
|
|
182
|
-
|
|
185
|
+
brandCheck(this, FormData);
|
|
183
186
|
this.#ensureArgs(args, 1, 'getAll');
|
|
184
187
|
const name = toUSVString(args[0]);
|
|
185
188
|
|
|
@@ -187,7 +190,7 @@ export class FormData {
|
|
|
187
190
|
}
|
|
188
191
|
|
|
189
192
|
has(...args) {
|
|
190
|
-
|
|
193
|
+
brandCheck(this, FormData);
|
|
191
194
|
this.#ensureArgs(args, 1, 'has');
|
|
192
195
|
const name = toUSVString(args[0]);
|
|
193
196
|
|
|
@@ -195,7 +198,7 @@ export class FormData {
|
|
|
195
198
|
}
|
|
196
199
|
|
|
197
200
|
set(...args) {
|
|
198
|
-
|
|
201
|
+
brandCheck(this, FormData);
|
|
199
202
|
this.#ensureArgs(args, 2, 'set');
|
|
200
203
|
const entry = this.constructor.#enfoldEntry(...args);
|
|
201
204
|
const idx = this.#entries.findIndex((it) => it.name === entry.name);
|
|
@@ -208,7 +211,7 @@ export class FormData {
|
|
|
208
211
|
}
|
|
209
212
|
|
|
210
213
|
* entries() {
|
|
211
|
-
|
|
214
|
+
brandCheck(this, FormData);
|
|
212
215
|
for (const { name, value } of this.#entries) {
|
|
213
216
|
yield [
|
|
214
217
|
name,
|
|
@@ -218,21 +221,21 @@ export class FormData {
|
|
|
218
221
|
}
|
|
219
222
|
|
|
220
223
|
* keys() {
|
|
221
|
-
|
|
224
|
+
brandCheck(this, FormData);
|
|
222
225
|
for (const [name] of this) {
|
|
223
226
|
yield name;
|
|
224
227
|
}
|
|
225
228
|
}
|
|
226
229
|
|
|
227
230
|
* values() {
|
|
228
|
-
|
|
231
|
+
brandCheck(this, FormData);
|
|
229
232
|
for (const [, value] of this) {
|
|
230
233
|
yield value;
|
|
231
234
|
}
|
|
232
235
|
}
|
|
233
236
|
|
|
234
237
|
[Symbol.iterator]() {
|
|
235
|
-
|
|
238
|
+
brandCheck(this, FormData);
|
|
236
239
|
|
|
237
240
|
return this.entries();
|
|
238
241
|
}
|