rekwest 3.2.0 → 3.3.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 +186 -184
- package/dist/ackn.js +2 -2
- package/dist/cookies.js +3 -0
- package/dist/file.js +4 -4
- package/dist/formdata.js +29 -15
- package/dist/index.js +50 -45
- package/dist/{helpers.js → utils.js} +77 -37
- package/package.json +5 -5
- package/src/ackn.mjs +33 -33
- package/src/cookies.mjs +4 -0
- package/src/file.mjs +2 -2
- package/src/formdata.mjs +239 -224
- package/src/index.mjs +17 -16
- package/src/{helpers.mjs → utils.mjs} +37 -13
package/dist/index.js
CHANGED
|
@@ -7,15 +7,15 @@ var _exportNames = {
|
|
|
7
7
|
exports.constants = void 0;
|
|
8
8
|
exports.default = rekwest;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _nodeHttp = _interopRequireDefault(require("node:http"));
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _nodeHttp2 = _interopRequireWildcard(require("node:http2"));
|
|
13
13
|
|
|
14
|
-
exports.constants =
|
|
14
|
+
exports.constants = _nodeHttp2.constants;
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _nodeHttps = _interopRequireDefault(require("node:https"));
|
|
17
17
|
|
|
18
|
-
var _promises = require("timers/promises");
|
|
18
|
+
var _promises = require("node:timers/promises");
|
|
19
19
|
|
|
20
20
|
var _ackn = require("./ackn.js");
|
|
21
21
|
|
|
@@ -44,17 +44,17 @@ Object.keys(_errors).forEach(function (key) {
|
|
|
44
44
|
exports[key] = _errors[key];
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
var
|
|
47
|
+
var _mediatypes = require("./mediatypes.js");
|
|
48
|
+
|
|
49
|
+
var _utils = require("./utils.js");
|
|
48
50
|
|
|
49
|
-
Object.keys(
|
|
51
|
+
Object.keys(_utils).forEach(function (key) {
|
|
50
52
|
if (key === "default" || key === "__esModule") return;
|
|
51
53
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
52
|
-
if (key in exports && exports[key] ===
|
|
53
|
-
exports[key] =
|
|
54
|
+
if (key in exports && exports[key] === _utils[key]) return;
|
|
55
|
+
exports[key] = _utils[key];
|
|
54
56
|
});
|
|
55
57
|
|
|
56
|
-
var _mediatypes = require("./mediatypes.js");
|
|
57
|
-
|
|
58
58
|
var _file = require("./file.js");
|
|
59
59
|
|
|
60
60
|
Object.keys(_file).forEach(function (key) {
|
|
@@ -92,7 +92,7 @@ const {
|
|
|
92
92
|
HTTP_STATUS_SEE_OTHER,
|
|
93
93
|
HTTP_STATUS_SERVICE_UNAVAILABLE,
|
|
94
94
|
HTTP_STATUS_TOO_MANY_REQUESTS
|
|
95
|
-
} =
|
|
95
|
+
} = _nodeHttp2.default.constants;
|
|
96
96
|
const maxRetryAfter = Symbol('maxRetryAfter');
|
|
97
97
|
|
|
98
98
|
const maxRetryAfterError = (interval, options) => new _errors.RequestError(`Maximum '${HTTP2_HEADER_RETRY_AFTER}' limit exceeded: ${interval} ms.`, options);
|
|
@@ -120,10 +120,15 @@ let defaults = {
|
|
|
120
120
|
};
|
|
121
121
|
|
|
122
122
|
async function rekwest(url, options = {}) {
|
|
123
|
-
|
|
123
|
+
({
|
|
124
|
+
url
|
|
125
|
+
} = (0, _utils.revise)({
|
|
126
|
+
options,
|
|
127
|
+
url
|
|
128
|
+
}));
|
|
124
129
|
|
|
125
130
|
if (!options.redirected) {
|
|
126
|
-
options = (0,
|
|
131
|
+
options = (0, _utils.merge)(rekwest.defaults, options);
|
|
127
132
|
}
|
|
128
133
|
|
|
129
134
|
if (options.body && [HTTP2_METHOD_GET, HTTP2_METHOD_HEAD].includes(options.method)) {
|
|
@@ -140,7 +145,7 @@ async function rekwest(url, options = {}) {
|
|
|
140
145
|
['alpnProtocol', 'createConnection', 'h2', 'protocol'].forEach(it => Reflect.deleteProperty(options, it));
|
|
141
146
|
}
|
|
142
147
|
|
|
143
|
-
options = (0,
|
|
148
|
+
options = (0, _utils.preflight)(options);
|
|
144
149
|
const {
|
|
145
150
|
cookies,
|
|
146
151
|
digest,
|
|
@@ -148,29 +153,26 @@ async function rekwest(url, options = {}) {
|
|
|
148
153
|
h2,
|
|
149
154
|
redirect,
|
|
150
155
|
redirected,
|
|
151
|
-
thenable
|
|
152
|
-
url: {
|
|
153
|
-
protocol
|
|
154
|
-
}
|
|
156
|
+
thenable
|
|
155
157
|
} = options;
|
|
156
158
|
const {
|
|
157
159
|
request
|
|
158
|
-
} = protocol === 'http:' ?
|
|
160
|
+
} = url.protocol === 'http:' ? _nodeHttp.default : _nodeHttps.default;
|
|
159
161
|
let {
|
|
160
162
|
body
|
|
161
163
|
} = options;
|
|
162
164
|
const promise = new Promise((resolve, reject) => {
|
|
163
165
|
let client, req;
|
|
164
|
-
body &&= (0,
|
|
166
|
+
body &&= (0, _utils.transform)(body, options);
|
|
165
167
|
|
|
166
168
|
if (h2) {
|
|
167
|
-
client =
|
|
169
|
+
client = _nodeHttp2.default.connect(url.origin, options);
|
|
168
170
|
req = client.request(options.headers, options);
|
|
169
171
|
} else {
|
|
170
172
|
req = request(url, options);
|
|
171
173
|
}
|
|
172
174
|
|
|
173
|
-
(0,
|
|
175
|
+
(0, _utils.affix)(client, req, options);
|
|
174
176
|
req.once('error', reject);
|
|
175
177
|
req.once('frameError', reject);
|
|
176
178
|
req.once('goaway', reject);
|
|
@@ -184,7 +186,7 @@ async function rekwest(url, options = {}) {
|
|
|
184
186
|
res.once('error', reject);
|
|
185
187
|
}
|
|
186
188
|
|
|
187
|
-
(0,
|
|
189
|
+
(0, _utils.admix)(res, headers, options);
|
|
188
190
|
|
|
189
191
|
if (cookies !== false && res.headers[HTTP2_HEADER_SET_COOKIE]) {
|
|
190
192
|
if (_cookies.Cookies.jar.has(url.origin)) {
|
|
@@ -202,11 +204,11 @@ async function rekwest(url, options = {}) {
|
|
|
202
204
|
});
|
|
203
205
|
|
|
204
206
|
if (follow && /^3\d{2}$/.test(res.statusCode) && res.headers[HTTP2_HEADER_LOCATION]) {
|
|
205
|
-
if (redirect ===
|
|
207
|
+
if (redirect === _utils.redirects.error) {
|
|
206
208
|
return res.emit('error', new _errors.RequestError(`Unexpected redirect, redirect mode is set to '${redirect}'.`));
|
|
207
209
|
}
|
|
208
210
|
|
|
209
|
-
if (redirect ===
|
|
211
|
+
if (redirect === _utils.redirects.follow) {
|
|
210
212
|
options.url = new URL(res.headers[HTTP2_HEADER_LOCATION], url).href;
|
|
211
213
|
|
|
212
214
|
if (res.statusCode !== HTTP_STATUS_SEE_OTHER && body === Object(body) && body.pipe?.constructor === Function) {
|
|
@@ -229,7 +231,7 @@ async function rekwest(url, options = {}) {
|
|
|
229
231
|
|
|
230
232
|
if (interval > options.maxRetryAfter) {
|
|
231
233
|
return res.emit('error', maxRetryAfterError(interval, {
|
|
232
|
-
cause: (0,
|
|
234
|
+
cause: (0, _utils.mixin)(res, options)
|
|
233
235
|
}));
|
|
234
236
|
}
|
|
235
237
|
|
|
@@ -241,12 +243,12 @@ async function rekwest(url, options = {}) {
|
|
|
241
243
|
}
|
|
242
244
|
|
|
243
245
|
if (res.statusCode >= HTTP_STATUS_BAD_REQUEST) {
|
|
244
|
-
return reject((0,
|
|
246
|
+
return reject((0, _utils.mixin)(res, options));
|
|
245
247
|
}
|
|
246
248
|
|
|
247
|
-
resolve((0,
|
|
249
|
+
resolve((0, _utils.mixin)(res, options));
|
|
248
250
|
});
|
|
249
|
-
(0,
|
|
251
|
+
(0, _utils.dispatch)(req, { ...options,
|
|
250
252
|
body
|
|
251
253
|
});
|
|
252
254
|
});
|
|
@@ -302,35 +304,37 @@ async function rekwest(url, options = {}) {
|
|
|
302
304
|
|
|
303
305
|
Reflect.defineProperty(rekwest, 'stream', {
|
|
304
306
|
enumerable: true,
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
307
|
+
|
|
308
|
+
value(url, options = {}) {
|
|
309
|
+
({
|
|
310
|
+
url
|
|
311
|
+
} = (0, _utils.revise)({
|
|
312
|
+
options,
|
|
313
|
+
url
|
|
314
|
+
}));
|
|
315
|
+
options = (0, _utils.preflight)({ ...(0, _utils.merge)(rekwest.defaults, {
|
|
309
316
|
headers: {
|
|
310
317
|
[HTTP2_HEADER_CONTENT_TYPE]: _mediatypes.APPLICATION_OCTET_STREAM
|
|
311
318
|
}
|
|
312
319
|
}, options),
|
|
313
|
-
redirect:
|
|
320
|
+
redirect: _utils.redirects.manual
|
|
314
321
|
});
|
|
315
322
|
const {
|
|
316
|
-
h2
|
|
317
|
-
url: {
|
|
318
|
-
protocol
|
|
319
|
-
}
|
|
323
|
+
h2
|
|
320
324
|
} = options;
|
|
321
325
|
const {
|
|
322
326
|
request
|
|
323
|
-
} = protocol === 'http:' ?
|
|
327
|
+
} = url.protocol === 'http:' ? _nodeHttp.default : _nodeHttps.default;
|
|
324
328
|
let client, req;
|
|
325
329
|
|
|
326
330
|
if (h2) {
|
|
327
|
-
client =
|
|
331
|
+
client = _nodeHttp2.default.connect(url.origin, options);
|
|
328
332
|
req = client.request(options.headers, options);
|
|
329
333
|
} else {
|
|
330
|
-
req = request(
|
|
334
|
+
req = request(url, options);
|
|
331
335
|
}
|
|
332
336
|
|
|
333
|
-
(0,
|
|
337
|
+
(0, _utils.affix)(client, req, options);
|
|
334
338
|
req.once('response', res => {
|
|
335
339
|
let headers;
|
|
336
340
|
|
|
@@ -339,10 +343,11 @@ Reflect.defineProperty(rekwest, 'stream', {
|
|
|
339
343
|
res = req;
|
|
340
344
|
}
|
|
341
345
|
|
|
342
|
-
(0,
|
|
346
|
+
(0, _utils.admix)(res, headers, options);
|
|
343
347
|
});
|
|
344
348
|
return req;
|
|
345
349
|
}
|
|
350
|
+
|
|
346
351
|
});
|
|
347
352
|
Reflect.defineProperty(rekwest, 'defaults', {
|
|
348
353
|
enumerable: true,
|
|
@@ -352,7 +357,7 @@ Reflect.defineProperty(rekwest, 'defaults', {
|
|
|
352
357
|
},
|
|
353
358
|
|
|
354
359
|
set(value) {
|
|
355
|
-
defaults = (0,
|
|
360
|
+
defaults = (0, _utils.merge)(defaults, value);
|
|
356
361
|
}
|
|
357
362
|
|
|
358
363
|
});
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports.redirects = exports.preflight = exports.mixin = exports.merge = exports.dispatch = exports.decompress = exports.compress = exports.affix = exports.admix = void 0;
|
|
4
|
+
exports.revise = exports.redirects = exports.preflight = exports.mixin = exports.merge = exports.dispatch = exports.decompress = exports.compress = exports.collate = exports.affix = exports.admix = void 0;
|
|
5
5
|
exports.tap = tap;
|
|
6
6
|
exports.transform = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _nodeBuffer = require("node:buffer");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _nodeHttp = _interopRequireDefault(require("node:http2"));
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _nodeStream = require("node:stream");
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _nodeUtil = require("node:util");
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _nodeZlib = _interopRequireDefault(require("node:zlib"));
|
|
17
17
|
|
|
18
18
|
var _cookies = require("./cookies.js");
|
|
19
19
|
|
|
@@ -41,13 +41,13 @@ const {
|
|
|
41
41
|
HTTP2_HEADER_STATUS,
|
|
42
42
|
HTTP2_METHOD_GET,
|
|
43
43
|
HTTP2_METHOD_HEAD
|
|
44
|
-
} =
|
|
45
|
-
const brotliCompress = (0,
|
|
46
|
-
const brotliDecompress = (0,
|
|
47
|
-
const gzip = (0,
|
|
48
|
-
const gunzip = (0,
|
|
49
|
-
const deflate = (0,
|
|
50
|
-
const inflate = (0,
|
|
44
|
+
} = _nodeHttp.default.constants;
|
|
45
|
+
const brotliCompress = (0, _nodeUtil.promisify)(_nodeZlib.default.brotliCompress);
|
|
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
51
|
|
|
52
52
|
const admix = (res, headers, options) => {
|
|
53
53
|
const {
|
|
@@ -94,14 +94,22 @@ const affix = (client, req, options) => {
|
|
|
94
94
|
|
|
95
95
|
exports.affix = affix;
|
|
96
96
|
|
|
97
|
+
const collate = (entity, primordial) => {
|
|
98
|
+
if (!(entity instanceof primordial)) {
|
|
99
|
+
throw new TypeError('Illegal invocation');
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
exports.collate = collate;
|
|
104
|
+
|
|
97
105
|
const compress = (buf, encoding, {
|
|
98
106
|
async = false
|
|
99
107
|
} = {}) => {
|
|
100
108
|
encoding &&= encoding.match(/(?<encoding>\bbr\b|\bdeflate\b|\bgzip\b)/i)?.groups.encoding.toLowerCase();
|
|
101
109
|
const compressor = {
|
|
102
|
-
br: async ? brotliCompress :
|
|
103
|
-
deflate: async ? deflate :
|
|
104
|
-
gzip: async ? gzip :
|
|
110
|
+
br: async ? brotliCompress : _nodeZlib.default.brotliCompressSync,
|
|
111
|
+
deflate: async ? deflate : _nodeZlib.default.deflateSync,
|
|
112
|
+
gzip: async ? gzip : _nodeZlib.default.gzipSync
|
|
105
113
|
}[encoding];
|
|
106
114
|
return compressor?.(buf) ?? (async ? Promise.resolve(buf) : buf);
|
|
107
115
|
};
|
|
@@ -113,9 +121,9 @@ const decompress = (buf, encoding, {
|
|
|
113
121
|
} = {}) => {
|
|
114
122
|
encoding &&= encoding.match(/(?<encoding>\bbr\b|\bdeflate\b|\bgzip\b)/i)?.groups.encoding.toLowerCase();
|
|
115
123
|
const decompressor = {
|
|
116
|
-
br: async ? brotliDecompress :
|
|
117
|
-
deflate: async ? inflate :
|
|
118
|
-
gzip: async ? gunzip :
|
|
124
|
+
br: async ? brotliDecompress : _nodeZlib.default.brotliDecompressSync,
|
|
125
|
+
deflate: async ? inflate : _nodeZlib.default.inflateSync,
|
|
126
|
+
gzip: async ? gunzip : _nodeZlib.default.gunzipSync
|
|
119
127
|
}[encoding];
|
|
120
128
|
return decompressor?.(buf) ?? (async ? Promise.resolve(buf) : buf);
|
|
121
129
|
};
|
|
@@ -128,14 +136,14 @@ const dispatch = (req, {
|
|
|
128
136
|
}) => {
|
|
129
137
|
if (body === Object(body) && !Buffer.isBuffer(body)) {
|
|
130
138
|
if (body.pipe?.constructor !== Function && (Reflect.has(body, Symbol.asyncIterator) || Reflect.has(body, Symbol.iterator))) {
|
|
131
|
-
body =
|
|
139
|
+
body = _nodeStream.Readable.from(body);
|
|
132
140
|
}
|
|
133
141
|
|
|
134
142
|
const compressor = {
|
|
135
|
-
br:
|
|
136
|
-
deflate:
|
|
137
|
-
gzip:
|
|
138
|
-
}[headers[HTTP2_HEADER_CONTENT_ENCODING]] ??
|
|
143
|
+
br: _nodeZlib.default.createBrotliCompress,
|
|
144
|
+
deflate: _nodeZlib.default.createDeflate,
|
|
145
|
+
gzip: _nodeZlib.default.createGzip
|
|
146
|
+
}[headers[HTTP2_HEADER_CONTENT_ENCODING]] ?? _nodeStream.PassThrough;
|
|
139
147
|
body.pipe(compressor()).pipe(req);
|
|
140
148
|
} else {
|
|
141
149
|
req.end(body);
|
|
@@ -179,7 +187,9 @@ const mixin = (res, {
|
|
|
179
187
|
Object.defineProperties(res, {
|
|
180
188
|
arrayBuffer: {
|
|
181
189
|
enumerable: true,
|
|
182
|
-
|
|
190
|
+
|
|
191
|
+
value() {
|
|
192
|
+
collate(this, res?.constructor);
|
|
183
193
|
parse &&= false;
|
|
184
194
|
return this.body().then(({
|
|
185
195
|
buffer,
|
|
@@ -187,24 +197,34 @@ const mixin = (res, {
|
|
|
187
197
|
byteOffset
|
|
188
198
|
}) => buffer.slice(byteOffset, byteOffset + byteLength));
|
|
189
199
|
}
|
|
200
|
+
|
|
190
201
|
},
|
|
191
202
|
blob: {
|
|
192
203
|
enumerable: true,
|
|
193
|
-
|
|
194
|
-
|
|
204
|
+
|
|
205
|
+
value() {
|
|
206
|
+
collate(this, res?.constructor);
|
|
207
|
+
return this.arrayBuffer().then(res => new _nodeBuffer.Blob([res]));
|
|
195
208
|
}
|
|
209
|
+
|
|
196
210
|
},
|
|
197
211
|
json: {
|
|
198
212
|
enumerable: true,
|
|
199
|
-
|
|
213
|
+
|
|
214
|
+
value() {
|
|
215
|
+
collate(this, res?.constructor);
|
|
200
216
|
return this.text().then(res => JSON.parse(res));
|
|
201
217
|
}
|
|
218
|
+
|
|
202
219
|
},
|
|
203
220
|
text: {
|
|
204
221
|
enumerable: true,
|
|
205
|
-
|
|
222
|
+
|
|
223
|
+
value() {
|
|
224
|
+
collate(this, res?.constructor);
|
|
206
225
|
return this.blob().then(blob => blob.text());
|
|
207
226
|
}
|
|
227
|
+
|
|
208
228
|
}
|
|
209
229
|
});
|
|
210
230
|
}
|
|
@@ -213,8 +233,10 @@ const mixin = (res, {
|
|
|
213
233
|
body: {
|
|
214
234
|
enumerable: true,
|
|
215
235
|
value: async function () {
|
|
236
|
+
collate(this, res?.constructor);
|
|
237
|
+
|
|
216
238
|
if (this.bodyUsed) {
|
|
217
|
-
throw new TypeError('Response stream already read
|
|
239
|
+
throw new TypeError('Response stream already read');
|
|
218
240
|
}
|
|
219
241
|
|
|
220
242
|
let spool = [];
|
|
@@ -252,9 +274,11 @@ const mixin = (res, {
|
|
|
252
274
|
},
|
|
253
275
|
bodyUsed: {
|
|
254
276
|
enumerable: true,
|
|
255
|
-
|
|
277
|
+
|
|
278
|
+
get() {
|
|
256
279
|
return this.readableEnded;
|
|
257
280
|
}
|
|
281
|
+
|
|
258
282
|
}
|
|
259
283
|
});
|
|
260
284
|
};
|
|
@@ -262,13 +286,13 @@ const mixin = (res, {
|
|
|
262
286
|
exports.mixin = mixin;
|
|
263
287
|
|
|
264
288
|
const preflight = options => {
|
|
265
|
-
const url = options.url = new URL(options.url);
|
|
266
289
|
const {
|
|
267
290
|
cookies,
|
|
268
291
|
h2 = false,
|
|
269
|
-
method = HTTP2_METHOD_GET,
|
|
270
292
|
headers,
|
|
271
|
-
|
|
293
|
+
method = HTTP2_METHOD_GET,
|
|
294
|
+
redirected,
|
|
295
|
+
url
|
|
272
296
|
} = options;
|
|
273
297
|
|
|
274
298
|
if (h2) {
|
|
@@ -333,6 +357,22 @@ const redirects = {
|
|
|
333
357
|
};
|
|
334
358
|
exports.redirects = redirects;
|
|
335
359
|
|
|
360
|
+
const revise = ({
|
|
361
|
+
url,
|
|
362
|
+
options
|
|
363
|
+
}) => {
|
|
364
|
+
if (options.trimTrailingSlashes) {
|
|
365
|
+
url = `${url}`.replace(/(?<!:)\/+/gi, '/');
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
url = new URL(url);
|
|
369
|
+
return Object.assign(options, {
|
|
370
|
+
url
|
|
371
|
+
});
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
exports.revise = revise;
|
|
375
|
+
|
|
336
376
|
async function* tap(value) {
|
|
337
377
|
if (Reflect.has(value, Symbol.asyncIterator)) {
|
|
338
378
|
yield* value;
|
|
@@ -346,9 +386,9 @@ async function* tap(value) {
|
|
|
346
386
|
const transform = (body, options) => {
|
|
347
387
|
let headers = {};
|
|
348
388
|
|
|
349
|
-
if (
|
|
389
|
+
if (_nodeUtil.types.isAnyArrayBuffer(body) && !Buffer.isBuffer(body)) {
|
|
350
390
|
body = Buffer.from(body);
|
|
351
|
-
} else if (
|
|
391
|
+
} else if (_nodeUtil.types.isArrayBufferView(body) && !Buffer.isBuffer(body)) {
|
|
352
392
|
body = Buffer.from(body.buffer, body.byteOffset, body.byteLength);
|
|
353
393
|
}
|
|
354
394
|
|
|
@@ -357,7 +397,7 @@ const transform = (body, options) => {
|
|
|
357
397
|
[HTTP2_HEADER_CONTENT_LENGTH]: body.size,
|
|
358
398
|
[HTTP2_HEADER_CONTENT_TYPE]: body.type || _mediatypes.APPLICATION_OCTET_STREAM
|
|
359
399
|
};
|
|
360
|
-
body = body.stream?.() ??
|
|
400
|
+
body = body.stream?.() ?? _nodeStream.Readable.from(tap(body));
|
|
361
401
|
} else if (_formdata.FormData.alike(body)) {
|
|
362
402
|
body = _formdata.FormData.actuate(body);
|
|
363
403
|
headers = {
|
package/package.json
CHANGED
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
"url": "https://github.com/bricss/rekwest/issues"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@babel/cli": "^7.17.
|
|
12
|
-
"@babel/core": "^7.17.
|
|
11
|
+
"@babel/cli": "^7.17.10",
|
|
12
|
+
"@babel/core": "^7.17.10",
|
|
13
13
|
"@babel/eslint-parser": "^7.17.0",
|
|
14
|
-
"@babel/preset-env": "^7.
|
|
14
|
+
"@babel/preset-env": "^7.17.10",
|
|
15
15
|
"c8": "^7.11.2",
|
|
16
16
|
"eslint": "^8.14.0",
|
|
17
17
|
"eslint-config-ultra-refined": "^2.5.0",
|
|
18
|
-
"mocha": "^
|
|
18
|
+
"mocha": "^10.0.0"
|
|
19
19
|
},
|
|
20
20
|
"description": "The robust request library that humanity deserves 🌐",
|
|
21
21
|
"engines": {
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"test:bail": "mocha --bail",
|
|
63
63
|
"test:cover": "c8 --include=src --reporter=lcov --reporter=text npm test"
|
|
64
64
|
},
|
|
65
|
-
"version": "3.
|
|
65
|
+
"version": "3.3.0"
|
|
66
66
|
}
|
package/src/ackn.mjs
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { connect } from 'tls';
|
|
2
|
-
|
|
3
|
-
export const ackn = (options) => new Promise((resolve, reject) => {
|
|
4
|
-
const { url } = options;
|
|
5
|
-
const socket = connect({
|
|
6
|
-
...options,
|
|
7
|
-
ALPNProtocols: [
|
|
8
|
-
'h2',
|
|
9
|
-
'http/1.1',
|
|
10
|
-
],
|
|
11
|
-
host: url.hostname,
|
|
12
|
-
port: parseInt(url.port) || 443,
|
|
13
|
-
servername: url.hostname,
|
|
14
|
-
}, () => {
|
|
15
|
-
socket.off('error', reject);
|
|
16
|
-
socket.off('timeout', reject);
|
|
17
|
-
|
|
18
|
-
const { alpnProtocol } = socket;
|
|
19
|
-
|
|
20
|
-
resolve({
|
|
21
|
-
...options,
|
|
22
|
-
alpnProtocol,
|
|
23
|
-
createConnection() {
|
|
24
|
-
return socket;
|
|
25
|
-
},
|
|
26
|
-
h2: /h2c?/.test(alpnProtocol),
|
|
27
|
-
protocol: url.protocol,
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
socket.on('error', reject);
|
|
32
|
-
socket.on('timeout', reject);
|
|
33
|
-
});
|
|
1
|
+
import { connect } from 'node:tls';
|
|
2
|
+
|
|
3
|
+
export const ackn = (options) => new Promise((resolve, reject) => {
|
|
4
|
+
const { url } = options;
|
|
5
|
+
const socket = connect({
|
|
6
|
+
...options,
|
|
7
|
+
ALPNProtocols: [
|
|
8
|
+
'h2',
|
|
9
|
+
'http/1.1',
|
|
10
|
+
],
|
|
11
|
+
host: url.hostname,
|
|
12
|
+
port: parseInt(url.port) || 443,
|
|
13
|
+
servername: url.hostname,
|
|
14
|
+
}, () => {
|
|
15
|
+
socket.off('error', reject);
|
|
16
|
+
socket.off('timeout', reject);
|
|
17
|
+
|
|
18
|
+
const { alpnProtocol } = socket;
|
|
19
|
+
|
|
20
|
+
resolve({
|
|
21
|
+
...options,
|
|
22
|
+
alpnProtocol,
|
|
23
|
+
createConnection() {
|
|
24
|
+
return socket;
|
|
25
|
+
},
|
|
26
|
+
h2: /h2c?/.test(alpnProtocol),
|
|
27
|
+
protocol: url.protocol,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
socket.on('error', reject);
|
|
32
|
+
socket.on('timeout', reject);
|
|
33
|
+
});
|
package/src/cookies.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { collate } from './utils.mjs';
|
|
2
|
+
|
|
1
3
|
export class Cookies extends URLSearchParams {
|
|
2
4
|
|
|
3
5
|
static jar = new Map();
|
|
@@ -18,6 +20,8 @@ export class Cookies extends URLSearchParams {
|
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
toString() {
|
|
23
|
+
collate(this, Cookies);
|
|
24
|
+
|
|
21
25
|
return super.toString().split('&').join('; ').trim();
|
|
22
26
|
}
|
|
23
27
|
|
package/src/file.mjs
CHANGED