rekwest 3.1.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 +57 -48
- package/dist/{helpers.js → utils.js} +77 -37
- package/package.json +11 -9
- 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 +20 -19
- 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) {
|
|
@@ -73,6 +73,10 @@ Object.keys(_formdata).forEach(function (key) {
|
|
|
73
73
|
exports[key] = _formdata[key];
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
77
|
+
|
|
78
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
79
|
+
|
|
76
80
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
77
81
|
|
|
78
82
|
const {
|
|
@@ -88,7 +92,7 @@ const {
|
|
|
88
92
|
HTTP_STATUS_SEE_OTHER,
|
|
89
93
|
HTTP_STATUS_SERVICE_UNAVAILABLE,
|
|
90
94
|
HTTP_STATUS_TOO_MANY_REQUESTS
|
|
91
|
-
} =
|
|
95
|
+
} = _nodeHttp2.default.constants;
|
|
92
96
|
const maxRetryAfter = Symbol('maxRetryAfter');
|
|
93
97
|
|
|
94
98
|
const maxRetryAfterError = (interval, options) => new _errors.RequestError(`Maximum '${HTTP2_HEADER_RETRY_AFTER}' limit exceeded: ${interval} ms.`, options);
|
|
@@ -116,10 +120,15 @@ let defaults = {
|
|
|
116
120
|
};
|
|
117
121
|
|
|
118
122
|
async function rekwest(url, options = {}) {
|
|
119
|
-
|
|
123
|
+
({
|
|
124
|
+
url
|
|
125
|
+
} = (0, _utils.revise)({
|
|
126
|
+
options,
|
|
127
|
+
url
|
|
128
|
+
}));
|
|
120
129
|
|
|
121
130
|
if (!options.redirected) {
|
|
122
|
-
options = (0,
|
|
131
|
+
options = (0, _utils.merge)(rekwest.defaults, options);
|
|
123
132
|
}
|
|
124
133
|
|
|
125
134
|
if (options.body && [HTTP2_METHOD_GET, HTTP2_METHOD_HEAD].includes(options.method)) {
|
|
@@ -136,7 +145,7 @@ async function rekwest(url, options = {}) {
|
|
|
136
145
|
['alpnProtocol', 'createConnection', 'h2', 'protocol'].forEach(it => Reflect.deleteProperty(options, it));
|
|
137
146
|
}
|
|
138
147
|
|
|
139
|
-
options = (0,
|
|
148
|
+
options = (0, _utils.preflight)(options);
|
|
140
149
|
const {
|
|
141
150
|
cookies,
|
|
142
151
|
digest,
|
|
@@ -144,29 +153,26 @@ async function rekwest(url, options = {}) {
|
|
|
144
153
|
h2,
|
|
145
154
|
redirect,
|
|
146
155
|
redirected,
|
|
147
|
-
thenable
|
|
148
|
-
url: {
|
|
149
|
-
protocol
|
|
150
|
-
}
|
|
156
|
+
thenable
|
|
151
157
|
} = options;
|
|
152
158
|
const {
|
|
153
159
|
request
|
|
154
|
-
} = protocol === 'http:' ?
|
|
160
|
+
} = url.protocol === 'http:' ? _nodeHttp.default : _nodeHttps.default;
|
|
155
161
|
let {
|
|
156
162
|
body
|
|
157
163
|
} = options;
|
|
158
164
|
const promise = new Promise((resolve, reject) => {
|
|
159
165
|
let client, req;
|
|
160
|
-
body &&= (0,
|
|
166
|
+
body &&= (0, _utils.transform)(body, options);
|
|
161
167
|
|
|
162
168
|
if (h2) {
|
|
163
|
-
client =
|
|
169
|
+
client = _nodeHttp2.default.connect(url.origin, options);
|
|
164
170
|
req = client.request(options.headers, options);
|
|
165
171
|
} else {
|
|
166
172
|
req = request(url, options);
|
|
167
173
|
}
|
|
168
174
|
|
|
169
|
-
(0,
|
|
175
|
+
(0, _utils.affix)(client, req, options);
|
|
170
176
|
req.once('error', reject);
|
|
171
177
|
req.once('frameError', reject);
|
|
172
178
|
req.once('goaway', reject);
|
|
@@ -180,7 +186,7 @@ async function rekwest(url, options = {}) {
|
|
|
180
186
|
res.once('error', reject);
|
|
181
187
|
}
|
|
182
188
|
|
|
183
|
-
(0,
|
|
189
|
+
(0, _utils.admix)(res, headers, options);
|
|
184
190
|
|
|
185
191
|
if (cookies !== false && res.headers[HTTP2_HEADER_SET_COOKIE]) {
|
|
186
192
|
if (_cookies.Cookies.jar.has(url.origin)) {
|
|
@@ -198,15 +204,15 @@ async function rekwest(url, options = {}) {
|
|
|
198
204
|
});
|
|
199
205
|
|
|
200
206
|
if (follow && /^3\d{2}$/.test(res.statusCode) && res.headers[HTTP2_HEADER_LOCATION]) {
|
|
201
|
-
if (redirect ===
|
|
202
|
-
res.emit('error', new _errors.RequestError(`Unexpected redirect, redirect mode is set to '${redirect}'.`));
|
|
207
|
+
if (redirect === _utils.redirects.error) {
|
|
208
|
+
return res.emit('error', new _errors.RequestError(`Unexpected redirect, redirect mode is set to '${redirect}'.`));
|
|
203
209
|
}
|
|
204
210
|
|
|
205
|
-
if (redirect ===
|
|
211
|
+
if (redirect === _utils.redirects.follow) {
|
|
206
212
|
options.url = new URL(res.headers[HTTP2_HEADER_LOCATION], url).href;
|
|
207
213
|
|
|
208
214
|
if (res.statusCode !== HTTP_STATUS_SEE_OTHER && body === Object(body) && body.pipe?.constructor === Function) {
|
|
209
|
-
res.emit('error', new _errors.RequestError(`Unable to ${redirect} redirect with body
|
|
215
|
+
return res.emit('error', new _errors.RequestError(`Unable to ${redirect} redirect with streamable body.`));
|
|
210
216
|
}
|
|
211
217
|
|
|
212
218
|
options.follow--;
|
|
@@ -224,8 +230,8 @@ async function rekwest(url, options = {}) {
|
|
|
224
230
|
interval = Number(interval) * 1000 || new Date(interval) - Date.now();
|
|
225
231
|
|
|
226
232
|
if (interval > options.maxRetryAfter) {
|
|
227
|
-
res.emit('error', maxRetryAfterError(interval, {
|
|
228
|
-
cause: (0,
|
|
233
|
+
return res.emit('error', maxRetryAfterError(interval, {
|
|
234
|
+
cause: (0, _utils.mixin)(res, options)
|
|
229
235
|
}));
|
|
230
236
|
}
|
|
231
237
|
|
|
@@ -237,12 +243,12 @@ async function rekwest(url, options = {}) {
|
|
|
237
243
|
}
|
|
238
244
|
|
|
239
245
|
if (res.statusCode >= HTTP_STATUS_BAD_REQUEST) {
|
|
240
|
-
return reject((0,
|
|
246
|
+
return reject((0, _utils.mixin)(res, options));
|
|
241
247
|
}
|
|
242
248
|
|
|
243
|
-
resolve((0,
|
|
249
|
+
resolve((0, _utils.mixin)(res, options));
|
|
244
250
|
});
|
|
245
|
-
(0,
|
|
251
|
+
(0, _utils.dispatch)(req, { ...options,
|
|
246
252
|
body
|
|
247
253
|
});
|
|
248
254
|
});
|
|
@@ -298,35 +304,37 @@ async function rekwest(url, options = {}) {
|
|
|
298
304
|
|
|
299
305
|
Reflect.defineProperty(rekwest, 'stream', {
|
|
300
306
|
enumerable: true,
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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, {
|
|
305
316
|
headers: {
|
|
306
317
|
[HTTP2_HEADER_CONTENT_TYPE]: _mediatypes.APPLICATION_OCTET_STREAM
|
|
307
318
|
}
|
|
308
319
|
}, options),
|
|
309
|
-
redirect:
|
|
320
|
+
redirect: _utils.redirects.manual
|
|
310
321
|
});
|
|
311
322
|
const {
|
|
312
|
-
h2
|
|
313
|
-
url: {
|
|
314
|
-
protocol
|
|
315
|
-
}
|
|
323
|
+
h2
|
|
316
324
|
} = options;
|
|
317
325
|
const {
|
|
318
326
|
request
|
|
319
|
-
} = protocol === 'http:' ?
|
|
327
|
+
} = url.protocol === 'http:' ? _nodeHttp.default : _nodeHttps.default;
|
|
320
328
|
let client, req;
|
|
321
329
|
|
|
322
330
|
if (h2) {
|
|
323
|
-
client =
|
|
331
|
+
client = _nodeHttp2.default.connect(url.origin, options);
|
|
324
332
|
req = client.request(options.headers, options);
|
|
325
333
|
} else {
|
|
326
|
-
req = request(
|
|
334
|
+
req = request(url, options);
|
|
327
335
|
}
|
|
328
336
|
|
|
329
|
-
(0,
|
|
337
|
+
(0, _utils.affix)(client, req, options);
|
|
330
338
|
req.once('response', res => {
|
|
331
339
|
let headers;
|
|
332
340
|
|
|
@@ -335,10 +343,11 @@ Reflect.defineProperty(rekwest, 'stream', {
|
|
|
335
343
|
res = req;
|
|
336
344
|
}
|
|
337
345
|
|
|
338
|
-
(0,
|
|
346
|
+
(0, _utils.admix)(res, headers, options);
|
|
339
347
|
});
|
|
340
348
|
return req;
|
|
341
349
|
}
|
|
350
|
+
|
|
342
351
|
});
|
|
343
352
|
Reflect.defineProperty(rekwest, 'defaults', {
|
|
344
353
|
enumerable: true,
|
|
@@ -348,7 +357,7 @@ Reflect.defineProperty(rekwest, 'defaults', {
|
|
|
348
357
|
},
|
|
349
358
|
|
|
350
359
|
set(value) {
|
|
351
|
-
defaults = (0,
|
|
360
|
+
defaults = (0, _utils.merge)(defaults, value);
|
|
352
361
|
}
|
|
353
362
|
|
|
354
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.
|
|
15
|
-
"c8": "^7.11.
|
|
16
|
-
"eslint": "^8.
|
|
17
|
-
"eslint-config-ultra-refined": "^2.
|
|
18
|
-
"mocha": "^
|
|
14
|
+
"@babel/preset-env": "^7.17.10",
|
|
15
|
+
"c8": "^7.11.2",
|
|
16
|
+
"eslint": "^8.14.0",
|
|
17
|
+
"eslint-config-ultra-refined": "^2.5.0",
|
|
18
|
+
"mocha": "^10.0.0"
|
|
19
19
|
},
|
|
20
20
|
"description": "The robust request library that humanity deserves 🌐",
|
|
21
21
|
"engines": {
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
],
|
|
32
32
|
"homepage": "https://github.com/bricss/rekwest#readme",
|
|
33
33
|
"keywords": [
|
|
34
|
+
"backoff",
|
|
34
35
|
"fetch",
|
|
35
36
|
"fetch-alike",
|
|
36
37
|
"formdata",
|
|
@@ -40,7 +41,8 @@
|
|
|
40
41
|
"h2c",
|
|
41
42
|
"http2",
|
|
42
43
|
"multipart",
|
|
43
|
-
"request"
|
|
44
|
+
"request",
|
|
45
|
+
"retry"
|
|
44
46
|
],
|
|
45
47
|
"license": "MIT",
|
|
46
48
|
"main": "./dist/index.js",
|
|
@@ -60,5 +62,5 @@
|
|
|
60
62
|
"test:bail": "mocha --bail",
|
|
61
63
|
"test:cover": "c8 --include=src --reporter=lcov --reporter=text npm test"
|
|
62
64
|
},
|
|
63
|
-
"version": "3.
|
|
65
|
+
"version": "3.3.0"
|
|
64
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