rekwest 3.3.4 → 4.1.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 +187 -186
- package/dist/ackn.js +4 -7
- package/dist/constants.js +21 -0
- package/dist/cookies.js +3 -11
- package/dist/errors.js +0 -7
- package/dist/file.js +9 -14
- package/dist/formdata.js +18 -65
- package/dist/index.js +54 -114
- package/dist/utils.js +117 -177
- package/package.json +13 -12
- package/src/constants.mjs +23 -0
- package/src/cookies.mjs +28 -28
- package/src/file.mjs +49 -40
- package/src/formdata.mjs +243 -239
- package/src/index.mjs +55 -27
- package/src/utils.mjs +104 -96
package/dist/utils.js
CHANGED
|
@@ -1,32 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports.
|
|
4
|
+
exports.sanitize = exports.sameOrigin = exports.preflight = exports.mixin = exports.merge = exports.dispatch = exports.decompress = exports.compress = exports.brandCheck = exports.affix = exports.admix = void 0;
|
|
5
5
|
exports.tap = tap;
|
|
6
6
|
exports.transform = void 0;
|
|
7
|
-
|
|
8
7
|
var _nodeBuffer = require("node:buffer");
|
|
9
|
-
|
|
10
8
|
var _nodeHttp = _interopRequireDefault(require("node:http2"));
|
|
11
|
-
|
|
12
9
|
var _nodeStream = require("node:stream");
|
|
13
|
-
|
|
10
|
+
var _consumers = require("node:stream/consumers");
|
|
14
11
|
var _nodeUtil = require("node:util");
|
|
15
|
-
|
|
16
12
|
var _nodeZlib = _interopRequireDefault(require("node:zlib"));
|
|
17
|
-
|
|
18
|
-
var _cookies = require("./cookies
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
var _formdata = require("./formdata.js");
|
|
25
|
-
|
|
26
|
-
var _mediatypes = require("./mediatypes.js");
|
|
27
|
-
|
|
13
|
+
var _constants = require("./constants");
|
|
14
|
+
var _cookies = require("./cookies");
|
|
15
|
+
var _errors = require("./errors");
|
|
16
|
+
var _file = require("./file");
|
|
17
|
+
var _formdata = require("./formdata");
|
|
18
|
+
var _mediatypes = require("./mediatypes");
|
|
28
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
-
|
|
30
20
|
const {
|
|
31
21
|
HTTP2_HEADER_ACCEPT,
|
|
32
22
|
HTTP2_HEADER_ACCEPT_ENCODING,
|
|
@@ -42,18 +32,11 @@ const {
|
|
|
42
32
|
HTTP2_METHOD_GET,
|
|
43
33
|
HTTP2_METHOD_HEAD
|
|
44
34
|
} = _nodeHttp.default.constants;
|
|
45
|
-
const
|
|
46
|
-
const brotliDecompress = (0, _nodeUtil.promisify)(_nodeZlib.default.brotliDecompress);
|
|
47
|
-
const gzip = (0, _nodeUtil.promisify)(_nodeZlib.default.gzip);
|
|
48
|
-
const gunzip = (0, _nodeUtil.promisify)(_nodeZlib.default.gunzip);
|
|
49
|
-
const deflate = (0, _nodeUtil.promisify)(_nodeZlib.default.deflate);
|
|
50
|
-
const inflate = (0, _nodeUtil.promisify)(_nodeZlib.default.inflate);
|
|
51
|
-
|
|
35
|
+
const unwind = encodings => encodings.split(',').map(it => it.trim());
|
|
52
36
|
const admix = (res, headers, options) => {
|
|
53
37
|
const {
|
|
54
38
|
h2
|
|
55
39
|
} = options;
|
|
56
|
-
|
|
57
40
|
if (h2) {
|
|
58
41
|
Reflect.defineProperty(res, 'headers', {
|
|
59
42
|
enumerable: true,
|
|
@@ -68,7 +51,6 @@ const admix = (res, headers, options) => {
|
|
|
68
51
|
value: headers[HTTP2_HEADER_STATUS]
|
|
69
52
|
});
|
|
70
53
|
}
|
|
71
|
-
|
|
72
54
|
Reflect.defineProperty(res, 'ok', {
|
|
73
55
|
enumerable: true,
|
|
74
56
|
value: /^2\d{2}$/.test(res.statusCode)
|
|
@@ -78,9 +60,7 @@ const admix = (res, headers, options) => {
|
|
|
78
60
|
value: !!options.redirected
|
|
79
61
|
});
|
|
80
62
|
};
|
|
81
|
-
|
|
82
63
|
exports.admix = admix;
|
|
83
|
-
|
|
84
64
|
const affix = (client, req, options) => {
|
|
85
65
|
req.once('end', () => client?.close());
|
|
86
66
|
req.once('timeout', () => req.destroy(new _errors.TimeoutError(`Timed out after ${options.timeout} ms.`)));
|
|
@@ -91,74 +71,66 @@ const affix = (client, req, options) => {
|
|
|
91
71
|
});
|
|
92
72
|
});
|
|
93
73
|
};
|
|
94
|
-
|
|
95
74
|
exports.affix = affix;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (entity?.constructor !== primordial) {
|
|
75
|
+
const brandCheck = (value, ctor) => {
|
|
76
|
+
if (!(value instanceof ctor)) {
|
|
99
77
|
throw new TypeError('Illegal invocation');
|
|
100
78
|
}
|
|
101
79
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
80
|
+
exports.brandCheck = brandCheck;
|
|
81
|
+
const compress = (readable, encodings = '') => {
|
|
82
|
+
const encoders = [];
|
|
83
|
+
encodings = unwind(encodings);
|
|
84
|
+
for (const encoding of encodings) {
|
|
85
|
+
if (/\bbr\b/i.test(encoding)) {
|
|
86
|
+
encoders.push(_nodeZlib.default.createBrotliCompress());
|
|
87
|
+
} else if (/\bdeflate(?!-(?:\w+)?)\b/i.test(encoding)) {
|
|
88
|
+
encoders.push(_nodeZlib.default.createDeflate());
|
|
89
|
+
} else if (/\bdeflate-raw\b/i.test(encoding)) {
|
|
90
|
+
encoders.push(_nodeZlib.default.createDeflateRaw());
|
|
91
|
+
} else if (/\bgzip\b/i.test(encoding)) {
|
|
92
|
+
encoders.push(_nodeZlib.default.createGzip());
|
|
93
|
+
} else {
|
|
94
|
+
return readable;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return (0, _nodeStream.pipeline)(readable, ...encoders, () => void 0);
|
|
115
98
|
};
|
|
116
|
-
|
|
117
99
|
exports.compress = compress;
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
100
|
+
const decompress = (readable, encodings = '') => {
|
|
101
|
+
const decoders = [];
|
|
102
|
+
encodings = unwind(encodings);
|
|
103
|
+
for (const encoding of encodings) {
|
|
104
|
+
if (/\bbr\b/i.test(encoding)) {
|
|
105
|
+
decoders.push(_nodeZlib.default.createBrotliDecompress());
|
|
106
|
+
} else if (/\bdeflate(?!-(?:\w+)?)\b/i.test(encoding)) {
|
|
107
|
+
decoders.push(_nodeZlib.default.createInflate());
|
|
108
|
+
} else if (/\bdeflate-raw\b/i.test(encoding)) {
|
|
109
|
+
decoders.push(_nodeZlib.default.createInflateRaw());
|
|
110
|
+
} else if (/\bgzip\b/i.test(encoding)) {
|
|
111
|
+
decoders.push(_nodeZlib.default.createGunzip());
|
|
112
|
+
} else {
|
|
113
|
+
return readable;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return (0, _nodeStream.pipeline)(readable, ...decoders, () => void 0);
|
|
129
117
|
};
|
|
130
|
-
|
|
131
118
|
exports.decompress = decompress;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (body === Object(body) && !Buffer.isBuffer(body)) {
|
|
138
|
-
if (body.pipe?.constructor !== Function && (Reflect.has(body, Symbol.asyncIterator) || Reflect.has(body, Symbol.iterator))) {
|
|
139
|
-
body = _nodeStream.Readable.from(body);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const compressor = {
|
|
143
|
-
br: _nodeZlib.default.createBrotliCompress,
|
|
144
|
-
deflate: _nodeZlib.default.createDeflate,
|
|
145
|
-
gzip: _nodeZlib.default.createGzip
|
|
146
|
-
}[headers[HTTP2_HEADER_CONTENT_ENCODING]] ?? _nodeStream.PassThrough;
|
|
147
|
-
body.pipe(compressor()).pipe(req);
|
|
119
|
+
const dispatch = ({
|
|
120
|
+
body
|
|
121
|
+
}, req) => {
|
|
122
|
+
if (body?.pipe?.constructor === Function) {
|
|
123
|
+
body.pipe(req);
|
|
148
124
|
} else {
|
|
149
125
|
req.end(body);
|
|
150
126
|
}
|
|
151
127
|
};
|
|
152
|
-
|
|
153
128
|
exports.dispatch = dispatch;
|
|
154
|
-
|
|
155
129
|
const merge = (target = {}, ...rest) => {
|
|
156
130
|
target = JSON.parse(JSON.stringify(target));
|
|
157
|
-
|
|
158
131
|
if (!rest.length) {
|
|
159
132
|
return target;
|
|
160
133
|
}
|
|
161
|
-
|
|
162
134
|
rest.filter(it => it === Object(it)).forEach(it => {
|
|
163
135
|
Object.entries(it).reduce((acc, [key, val]) => {
|
|
164
136
|
if ([acc[key]?.constructor, val?.constructor].every(it => [Array, Object].includes(it))) {
|
|
@@ -170,15 +142,12 @@ const merge = (target = {}, ...rest) => {
|
|
|
170
142
|
} else {
|
|
171
143
|
acc[key] = val;
|
|
172
144
|
}
|
|
173
|
-
|
|
174
145
|
return acc;
|
|
175
146
|
}, target);
|
|
176
147
|
});
|
|
177
148
|
return target;
|
|
178
149
|
};
|
|
179
|
-
|
|
180
150
|
exports.merge = merge;
|
|
181
|
-
|
|
182
151
|
const mixin = (res, {
|
|
183
152
|
digest = false,
|
|
184
153
|
parse = false
|
|
@@ -188,7 +157,7 @@ const mixin = (res, {
|
|
|
188
157
|
arrayBuffer: {
|
|
189
158
|
enumerable: true,
|
|
190
159
|
value: async function () {
|
|
191
|
-
|
|
160
|
+
brandCheck(this, res?.constructor);
|
|
192
161
|
parse &&= false;
|
|
193
162
|
const {
|
|
194
163
|
buffer,
|
|
@@ -201,7 +170,7 @@ const mixin = (res, {
|
|
|
201
170
|
blob: {
|
|
202
171
|
enumerable: true,
|
|
203
172
|
value: async function () {
|
|
204
|
-
|
|
173
|
+
brandCheck(this, res?.constructor);
|
|
205
174
|
const val = await this.arrayBuffer();
|
|
206
175
|
return new _nodeBuffer.Blob([val]);
|
|
207
176
|
}
|
|
@@ -209,7 +178,7 @@ const mixin = (res, {
|
|
|
209
178
|
json: {
|
|
210
179
|
enumerable: true,
|
|
211
180
|
value: async function () {
|
|
212
|
-
|
|
181
|
+
brandCheck(this, res?.constructor);
|
|
213
182
|
const val = await this.text();
|
|
214
183
|
return JSON.parse(val);
|
|
215
184
|
}
|
|
@@ -217,70 +186,55 @@ const mixin = (res, {
|
|
|
217
186
|
text: {
|
|
218
187
|
enumerable: true,
|
|
219
188
|
value: async function () {
|
|
220
|
-
|
|
189
|
+
brandCheck(this, res?.constructor);
|
|
221
190
|
const blob = await this.blob();
|
|
222
191
|
return blob.text();
|
|
223
192
|
}
|
|
224
193
|
}
|
|
225
194
|
});
|
|
226
195
|
}
|
|
227
|
-
|
|
228
196
|
return Object.defineProperties(res, {
|
|
229
197
|
body: {
|
|
230
198
|
enumerable: true,
|
|
231
199
|
value: async function () {
|
|
232
|
-
|
|
233
|
-
|
|
200
|
+
brandCheck(this, res?.constructor);
|
|
234
201
|
if (this.bodyUsed) {
|
|
235
202
|
throw new TypeError('Response stream already read');
|
|
236
203
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
for await (const chunk of this) {
|
|
241
|
-
spool.push(chunk);
|
|
204
|
+
let body = [];
|
|
205
|
+
for await (const chunk of decompress(this, this.headers[HTTP2_HEADER_CONTENT_ENCODING])) {
|
|
206
|
+
body.push(chunk);
|
|
242
207
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
if (spool.length) {
|
|
247
|
-
spool = await decompress(spool, this.headers[HTTP2_HEADER_CONTENT_ENCODING], {
|
|
248
|
-
async: true
|
|
249
|
-
});
|
|
208
|
+
body = Buffer.concat(body);
|
|
209
|
+
if (!body.length && parse) {
|
|
210
|
+
return null;
|
|
250
211
|
}
|
|
251
|
-
|
|
252
|
-
if (spool.length && parse) {
|
|
212
|
+
if (body.length && parse) {
|
|
253
213
|
const contentType = this.headers[HTTP2_HEADER_CONTENT_TYPE] ?? '';
|
|
254
214
|
const charset = contentType.split(';').find(it => /charset=/i.test(it))?.toLowerCase().replace('charset=', '').replace('iso-8859-1', 'latin1').trim() || 'utf-8';
|
|
255
|
-
|
|
256
215
|
if (/\bjson\b/i.test(contentType)) {
|
|
257
|
-
|
|
258
|
-
} else if (/\b(text|xml)\b/i.test(contentType)) {
|
|
259
|
-
if (/\b(latin1|ucs-2|utf-(8|16le))\b/.test(charset)) {
|
|
260
|
-
|
|
216
|
+
body = JSON.parse(body.toString(charset));
|
|
217
|
+
} else if (/\b(?:text|xml)\b/i.test(contentType)) {
|
|
218
|
+
if (/\b(?:latin1|ucs-2|utf-(?:8|16le))\b/.test(charset)) {
|
|
219
|
+
body = body.toString(charset);
|
|
261
220
|
} else {
|
|
262
|
-
|
|
221
|
+
body = new TextDecoder(charset).decode(body);
|
|
263
222
|
}
|
|
264
223
|
}
|
|
265
224
|
}
|
|
266
|
-
|
|
267
|
-
return spool;
|
|
225
|
+
return body;
|
|
268
226
|
},
|
|
269
227
|
writable: true
|
|
270
228
|
},
|
|
271
229
|
bodyUsed: {
|
|
272
230
|
enumerable: true,
|
|
273
|
-
|
|
274
231
|
get() {
|
|
275
232
|
return this.readableEnded;
|
|
276
233
|
}
|
|
277
|
-
|
|
278
234
|
}
|
|
279
235
|
});
|
|
280
236
|
};
|
|
281
|
-
|
|
282
237
|
exports.mixin = mixin;
|
|
283
|
-
|
|
284
238
|
const preflight = options => {
|
|
285
239
|
const {
|
|
286
240
|
cookies,
|
|
@@ -290,14 +244,11 @@ const preflight = options => {
|
|
|
290
244
|
redirected,
|
|
291
245
|
url
|
|
292
246
|
} = options;
|
|
293
|
-
|
|
294
247
|
if (h2) {
|
|
295
248
|
options.endStream = [HTTP2_METHOD_GET, HTTP2_METHOD_HEAD].includes(method);
|
|
296
249
|
}
|
|
297
|
-
|
|
298
250
|
if (cookies !== false) {
|
|
299
251
|
let cookie = _cookies.Cookies.jar.get(url.origin);
|
|
300
|
-
|
|
301
252
|
if (cookies === Object(cookies) && !redirected) {
|
|
302
253
|
if (cookie) {
|
|
303
254
|
new _cookies.Cookies(cookies).forEach(function (val, key) {
|
|
@@ -305,24 +256,22 @@ const preflight = options => {
|
|
|
305
256
|
}, cookie);
|
|
306
257
|
} else {
|
|
307
258
|
cookie = new _cookies.Cookies(cookies);
|
|
308
|
-
|
|
309
259
|
_cookies.Cookies.jar.set(url.origin, cookie);
|
|
310
260
|
}
|
|
311
261
|
}
|
|
312
|
-
|
|
313
|
-
|
|
262
|
+
options.headers = {
|
|
263
|
+
...(cookie && {
|
|
314
264
|
[HTTP2_HEADER_COOKIE]: cookie
|
|
315
265
|
}),
|
|
316
266
|
...headers
|
|
317
267
|
};
|
|
318
268
|
}
|
|
319
|
-
|
|
320
269
|
options.digest ??= true;
|
|
321
270
|
options.follow ??= 20;
|
|
322
271
|
options.h2 ??= h2;
|
|
323
272
|
options.headers = {
|
|
324
273
|
[HTTP2_HEADER_ACCEPT]: `${_mediatypes.APPLICATION_JSON}, ${_mediatypes.TEXT_PLAIN}, ${_mediatypes.WILDCARD}`,
|
|
325
|
-
[HTTP2_HEADER_ACCEPT_ENCODING]: 'br, deflate, gzip, identity',
|
|
274
|
+
[HTTP2_HEADER_ACCEPT_ENCODING]: 'br, deflate, deflate-raw, gzip, identity',
|
|
326
275
|
...Object.entries(options.headers ?? {}).reduce((acc, [key, val]) => (acc[key.toLowerCase()] = val, acc), {}),
|
|
327
276
|
...(h2 && {
|
|
328
277
|
[HTTP2_HEADER_AUTHORITY]: url.host,
|
|
@@ -333,42 +282,28 @@ const preflight = options => {
|
|
|
333
282
|
};
|
|
334
283
|
options.method ??= method;
|
|
335
284
|
options.parse ??= true;
|
|
336
|
-
options.redirect ??=
|
|
337
|
-
|
|
338
|
-
if (!Object.values(redirects).includes(options.redirect)) {
|
|
285
|
+
options.redirect ??= _constants.redirectModes.follow;
|
|
286
|
+
if (!Reflect.has(_constants.redirectModes, options.redirect)) {
|
|
339
287
|
options.createConnection?.().destroy();
|
|
340
288
|
throw new TypeError(`Failed to read the 'redirect' property from 'options': The provided value '${options.redirect}' is not a valid enum value.`);
|
|
341
289
|
}
|
|
342
|
-
|
|
343
290
|
options.redirected ??= false;
|
|
344
291
|
options.thenable ??= false;
|
|
345
292
|
return options;
|
|
346
293
|
};
|
|
347
|
-
|
|
348
294
|
exports.preflight = preflight;
|
|
349
|
-
const
|
|
350
|
-
error: 'error',
|
|
351
|
-
follow: 'follow',
|
|
352
|
-
manual: 'manual'
|
|
353
|
-
};
|
|
354
|
-
exports.redirects = redirects;
|
|
355
|
-
|
|
356
|
-
const revise = ({
|
|
357
|
-
url,
|
|
358
|
-
options
|
|
359
|
-
}) => {
|
|
295
|
+
const sanitize = (url, options = {}) => {
|
|
360
296
|
if (options.trimTrailingSlashes) {
|
|
361
297
|
url = `${url}`.replace(/(?<!:)\/+/gi, '/');
|
|
362
298
|
}
|
|
363
|
-
|
|
364
299
|
url = new URL(url);
|
|
365
300
|
return Object.assign(options, {
|
|
366
301
|
url
|
|
367
302
|
});
|
|
368
303
|
};
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
304
|
+
exports.sanitize = sanitize;
|
|
305
|
+
const sameOrigin = (a, b) => a.protocol === b.protocol && a.hostname === b.hostname && a.port === b.port;
|
|
306
|
+
exports.sameOrigin = sameOrigin;
|
|
372
307
|
async function* tap(value) {
|
|
373
308
|
if (Reflect.has(value, Symbol.asyncIterator)) {
|
|
374
309
|
yield* value;
|
|
@@ -378,57 +313,62 @@ async function* tap(value) {
|
|
|
378
313
|
yield await value.arrayBuffer();
|
|
379
314
|
}
|
|
380
315
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
body = Buffer.from(body.buffer, body.byteOffset, body.byteLength);
|
|
316
|
+
const transform = async options => {
|
|
317
|
+
let {
|
|
318
|
+
body,
|
|
319
|
+
headers
|
|
320
|
+
} = options;
|
|
321
|
+
if (!body) {
|
|
322
|
+
return options;
|
|
389
323
|
}
|
|
390
|
-
|
|
391
324
|
if (_file.File.alike(body)) {
|
|
392
325
|
headers = {
|
|
393
326
|
[HTTP2_HEADER_CONTENT_LENGTH]: body.size,
|
|
394
327
|
[HTTP2_HEADER_CONTENT_TYPE]: body.type || _mediatypes.APPLICATION_OCTET_STREAM
|
|
395
328
|
};
|
|
396
|
-
body = body.stream
|
|
329
|
+
body = body.stream();
|
|
397
330
|
} else if (_formdata.FormData.alike(body)) {
|
|
398
331
|
body = _formdata.FormData.actuate(body);
|
|
399
332
|
headers = {
|
|
400
333
|
[HTTP2_HEADER_CONTENT_TYPE]: body.contentType
|
|
401
334
|
};
|
|
402
|
-
} else if (
|
|
403
|
-
if (body
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
body =
|
|
335
|
+
} else if (!Buffer.isBuffer(body)) {
|
|
336
|
+
if (_nodeUtil.types.isAnyArrayBuffer(body)) {
|
|
337
|
+
body = Buffer.from(body);
|
|
338
|
+
} else if (_nodeUtil.types.isArrayBufferView(body)) {
|
|
339
|
+
body = Buffer.from(body.buffer, body.byteOffset, body.byteLength);
|
|
340
|
+
} else if (body === Object(body) && !Reflect.has(body, Symbol.asyncIterator)) {
|
|
341
|
+
if (body.constructor === URLSearchParams) {
|
|
342
|
+
headers = {
|
|
343
|
+
[HTTP2_HEADER_CONTENT_TYPE]: _mediatypes.APPLICATION_FORM_URLENCODED
|
|
344
|
+
};
|
|
345
|
+
body = body.toString();
|
|
346
|
+
} else if (!(!Array.isArray(body) && Reflect.has(body, Symbol.iterator))) {
|
|
347
|
+
headers = {
|
|
348
|
+
[HTTP2_HEADER_CONTENT_TYPE]: _mediatypes.APPLICATION_JSON
|
|
349
|
+
};
|
|
350
|
+
body = JSON.stringify(body);
|
|
418
351
|
}
|
|
419
|
-
|
|
420
|
-
headers = { ...headers,
|
|
421
|
-
[HTTP2_HEADER_CONTENT_LENGTH]: Buffer.byteLength(body)
|
|
422
|
-
};
|
|
423
352
|
}
|
|
424
353
|
}
|
|
425
|
-
|
|
426
|
-
Object.
|
|
354
|
+
const encodings = options.headers[HTTP2_HEADER_CONTENT_ENCODING];
|
|
355
|
+
if (body === Object(body) && (Reflect.has(body, Symbol.asyncIterator) || !Array.isArray(body) && Reflect.has(body, Symbol.iterator))) {
|
|
356
|
+
body = encodings ? compress(_nodeStream.Readable.from(body), encodings) : _nodeStream.Readable.from(body);
|
|
357
|
+
} else if (encodings) {
|
|
358
|
+
body = await (0, _consumers.buffer)(compress(_nodeStream.Readable.from(body), encodings));
|
|
359
|
+
}
|
|
360
|
+
Object.assign(options.headers, {
|
|
361
|
+
...headers,
|
|
362
|
+
...(!body[Symbol.asyncIterator] && {
|
|
363
|
+
[HTTP2_HEADER_CONTENT_LENGTH]: Buffer.byteLength(body)
|
|
364
|
+
}),
|
|
427
365
|
...(options.headers[HTTP2_HEADER_CONTENT_TYPE] && {
|
|
428
366
|
[HTTP2_HEADER_CONTENT_TYPE]: options.headers[HTTP2_HEADER_CONTENT_TYPE]
|
|
429
367
|
})
|
|
430
368
|
});
|
|
431
|
-
return
|
|
369
|
+
return {
|
|
370
|
+
...options,
|
|
371
|
+
body
|
|
372
|
+
};
|
|
432
373
|
};
|
|
433
|
-
|
|
434
374
|
exports.transform = transform;
|
package/package.json
CHANGED
|
@@ -8,18 +8,18 @@
|
|
|
8
8
|
"url": "https://github.com/bricss/rekwest/issues"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@babel/cli": "^7.
|
|
12
|
-
"@babel/core": "^7.
|
|
11
|
+
"@babel/cli": "^7.19.3",
|
|
12
|
+
"@babel/core": "^7.20.5",
|
|
13
13
|
"@babel/eslint-parser": "^7.19.1",
|
|
14
|
-
"@babel/preset-env": "^7.
|
|
14
|
+
"@babel/preset-env": "^7.20.2",
|
|
15
15
|
"c8": "^7.12.0",
|
|
16
|
-
"eslint": "^8.
|
|
17
|
-
"eslint-config-ultra-refined": "^2.
|
|
18
|
-
"mocha": "^10.
|
|
16
|
+
"eslint": "^8.28.0",
|
|
17
|
+
"eslint-config-ultra-refined": "^2.10.0",
|
|
18
|
+
"mocha": "^10.1.0"
|
|
19
19
|
},
|
|
20
20
|
"description": "The robust request library that humanity deserves 🌐",
|
|
21
21
|
"engines": {
|
|
22
|
-
"node": ">=16.
|
|
22
|
+
"node": ">=16.7.x"
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
25
|
"import": "./src/index.mjs",
|
|
@@ -32,11 +32,12 @@
|
|
|
32
32
|
"homepage": "https://github.com/bricss/rekwest#readme",
|
|
33
33
|
"keywords": [
|
|
34
34
|
"backoff",
|
|
35
|
-
"
|
|
35
|
+
"brotli",
|
|
36
36
|
"cookie",
|
|
37
|
+
"deflate",
|
|
37
38
|
"fetch",
|
|
38
|
-
"fetch-alike",
|
|
39
39
|
"formdata",
|
|
40
|
+
"gzip",
|
|
40
41
|
"http",
|
|
41
42
|
"https",
|
|
42
43
|
"h2",
|
|
@@ -46,10 +47,10 @@
|
|
|
46
47
|
"request",
|
|
47
48
|
"redirect",
|
|
48
49
|
"retry",
|
|
49
|
-
"retry-after"
|
|
50
|
+
"retry-after",
|
|
51
|
+
"stream"
|
|
50
52
|
],
|
|
51
53
|
"license": "MIT",
|
|
52
|
-
"main": "./dist/index.js",
|
|
53
54
|
"name": "rekwest",
|
|
54
55
|
"repository": {
|
|
55
56
|
"type": "git",
|
|
@@ -66,5 +67,5 @@
|
|
|
66
67
|
"test:bail": "mocha --bail",
|
|
67
68
|
"test:cover": "c8 --include=src --reporter=lcov --reporter=text npm test"
|
|
68
69
|
},
|
|
69
|
-
"version": "
|
|
70
|
+
"version": "4.1.0"
|
|
70
71
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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 redirectModes = {
|
|
12
|
+
error: 'error',
|
|
13
|
+
follow: 'follow',
|
|
14
|
+
manual: 'manual',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const redirectStatusCodes = [
|
|
18
|
+
HTTP_STATUS_MOVED_PERMANENTLY,
|
|
19
|
+
HTTP_STATUS_FOUND,
|
|
20
|
+
HTTP_STATUS_SEE_OTHER,
|
|
21
|
+
HTTP_STATUS_TEMPORARY_REDIRECT,
|
|
22
|
+
HTTP_STATUS_PERMANENT_REDIRECT,
|
|
23
|
+
];
|
package/src/cookies.mjs
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export class Cookies extends URLSearchParams {
|
|
4
|
-
|
|
5
|
-
static jar = new Map();
|
|
6
|
-
|
|
7
|
-
get [Symbol.toStringTag]() {
|
|
8
|
-
return this.constructor.name;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
constructor(input) {
|
|
12
|
-
if (Array.isArray(input) && input.every((it) => !Array.isArray(it))) {
|
|
13
|
-
input = input.join(';').split(';')
|
|
14
|
-
.filter((it) => !/\b(Domain|Expires|HttpOnly|Max-Age|Path|SameParty|SameSite|Secure)\b/i.test(it))
|
|
15
|
-
.map((it) => it.trim())
|
|
16
|
-
.join('&');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
super(input);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
toString() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return super.toString().split('&').join('; ').trim();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
}
|
|
1
|
+
import { brandCheck } from './utils.mjs';
|
|
2
|
+
|
|
3
|
+
export class Cookies extends URLSearchParams {
|
|
4
|
+
|
|
5
|
+
static jar = new Map();
|
|
6
|
+
|
|
7
|
+
get [Symbol.toStringTag]() {
|
|
8
|
+
return this.constructor.name;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
constructor(input) {
|
|
12
|
+
if (Array.isArray(input) && input.every((it) => !Array.isArray(it))) {
|
|
13
|
+
input = input.join(';').split(';')
|
|
14
|
+
.filter((it) => !/\b(?:Domain|Expires|HttpOnly|Max-Age|Path|SameParty|SameSite|Secure)\b/i.test(it))
|
|
15
|
+
.map((it) => it.trim())
|
|
16
|
+
.join('&');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
super(input);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
toString() {
|
|
23
|
+
brandCheck(this, Cookies);
|
|
24
|
+
|
|
25
|
+
return super.toString().split('&').join('; ').trim();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
}
|