rekwest 4.2.0 → 4.2.1
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/dist/index.js +3 -3
- package/dist/postflight.js +1 -0
- package/dist/preflight.js +1 -2
- package/dist/utils.js +13 -11
- package/package.json +1 -1
- package/src/index.mjs +85 -84
- package/src/postflight.mjs +1 -0
- package/src/preflight.mjs +1 -2
- package/src/utils.mjs +9 -6
package/dist/index.js
CHANGED
|
@@ -93,14 +93,14 @@ Reflect.defineProperty(rekwest, 'stream', {
|
|
|
93
93
|
h2,
|
|
94
94
|
url
|
|
95
95
|
} = options;
|
|
96
|
-
const {
|
|
97
|
-
request
|
|
98
|
-
} = url.protocol === 'http:' ? _nodeHttp.default : _nodeHttps.default;
|
|
99
96
|
let client, req;
|
|
100
97
|
if (h2) {
|
|
101
98
|
client = _nodeHttp2.default.connect(url.origin, options);
|
|
102
99
|
req = client.request(options.headers, options);
|
|
103
100
|
} else {
|
|
101
|
+
const {
|
|
102
|
+
request
|
|
103
|
+
} = url.protocol === 'http:' ? _nodeHttp.default : _nodeHttps.default;
|
|
104
104
|
req = request(url, options);
|
|
105
105
|
}
|
|
106
106
|
(0, _utils.affix)(client, req, options);
|
package/dist/postflight.js
CHANGED
|
@@ -88,6 +88,7 @@ const postflight = (req, res, options, {
|
|
|
88
88
|
options.body = null;
|
|
89
89
|
options.method = HTTP2_METHOD_GET;
|
|
90
90
|
}
|
|
91
|
+
Reflect.set(options, 'h2', false);
|
|
91
92
|
Reflect.set(options, 'redirected', true);
|
|
92
93
|
if (statusCode === HTTP_STATUS_MOVED_PERMANENTLY && res.headers[HTTP2_HEADER_RETRY_AFTER]) {
|
|
93
94
|
let interval = res.headers[HTTP2_HEADER_RETRY_AFTER];
|
package/dist/preflight.js
CHANGED
|
@@ -22,7 +22,7 @@ const preflight = options => {
|
|
|
22
22
|
const {
|
|
23
23
|
cookies,
|
|
24
24
|
credentials,
|
|
25
|
-
h2
|
|
25
|
+
h2,
|
|
26
26
|
headers,
|
|
27
27
|
method,
|
|
28
28
|
url
|
|
@@ -49,7 +49,6 @@ const preflight = options => {
|
|
|
49
49
|
...headers
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
-
options.h2 ??= h2;
|
|
53
52
|
options.headers = {
|
|
54
53
|
[HTTP2_HEADER_ACCEPT]: `${_mediatypes.APPLICATION_JSON}, ${_mediatypes.TEXT_PLAIN}, ${_mediatypes.WILDCARD}`,
|
|
55
54
|
[HTTP2_HEADER_ACCEPT_ENCODING]: 'br, deflate, deflate-raw, gzip, identity',
|
package/dist/utils.js
CHANGED
|
@@ -261,13 +261,21 @@ async function* tap(value) {
|
|
|
261
261
|
}
|
|
262
262
|
const transfer = async options => {
|
|
263
263
|
const {
|
|
264
|
+
digest,
|
|
265
|
+
h2,
|
|
266
|
+
redirected,
|
|
267
|
+
thenable,
|
|
264
268
|
url
|
|
265
269
|
} = options;
|
|
266
270
|
if (options.follow === 0) {
|
|
267
271
|
throw new _errors.RequestError(`Maximum redirect reached at: ${url.href}`);
|
|
268
272
|
}
|
|
269
273
|
if (url.protocol === 'https:') {
|
|
270
|
-
options = await (0, _ackn.ackn)(options)
|
|
274
|
+
options = !h2 ? await (0, _ackn.ackn)(options) : {
|
|
275
|
+
...options,
|
|
276
|
+
createConnection: null,
|
|
277
|
+
protocol: url.protocol
|
|
278
|
+
};
|
|
271
279
|
} else if (Reflect.has(options, 'alpnProtocol')) {
|
|
272
280
|
['alpnProtocol', 'createConnection', 'h2', 'protocol'].forEach(it => Reflect.deleteProperty(options, it));
|
|
273
281
|
}
|
|
@@ -277,21 +285,15 @@ const transfer = async options => {
|
|
|
277
285
|
options.createConnection?.().destroy();
|
|
278
286
|
throw ex;
|
|
279
287
|
}
|
|
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
288
|
const promise = new Promise((resolve, reject) => {
|
|
290
289
|
let client, req;
|
|
291
|
-
if (h2) {
|
|
290
|
+
if (options.h2) {
|
|
292
291
|
client = _nodeHttp2.default.connect(url.origin, options);
|
|
293
292
|
req = client.request(options.headers, options);
|
|
294
293
|
} else {
|
|
294
|
+
const {
|
|
295
|
+
request
|
|
296
|
+
} = url.protocol === 'http:' ? _nodeHttp.default : _nodeHttps.default;
|
|
295
297
|
req = request(url, options);
|
|
296
298
|
}
|
|
297
299
|
affix(client, req, options);
|
package/package.json
CHANGED
package/src/index.mjs
CHANGED
|
@@ -1,84 +1,85 @@
|
|
|
1
|
-
import http from 'node:http';
|
|
2
|
-
import http2 from 'node:http2';
|
|
3
|
-
import https from 'node:https';
|
|
4
|
-
import { requestRedirect } from './constants.mjs';
|
|
5
|
-
import defaults from './defaults.mjs';
|
|
6
|
-
import { APPLICATION_OCTET_STREAM } from './mediatypes.mjs';
|
|
7
|
-
import { preflight } from './preflight.mjs';
|
|
8
|
-
import {
|
|
9
|
-
admix,
|
|
10
|
-
affix,
|
|
11
|
-
merge,
|
|
12
|
-
sanitize,
|
|
13
|
-
transfer,
|
|
14
|
-
validation,
|
|
15
|
-
} from './utils.mjs';
|
|
16
|
-
|
|
17
|
-
export { constants } from 'node:http2';
|
|
18
|
-
|
|
19
|
-
export * from './ackn.mjs';
|
|
20
|
-
export * from './constants.mjs';
|
|
21
|
-
export * from './cookies.mjs';
|
|
22
|
-
export * from './errors.mjs';
|
|
23
|
-
export * from './file.mjs';
|
|
24
|
-
export * from './formdata.mjs';
|
|
25
|
-
export * as mediatypes from './mediatypes.mjs';
|
|
26
|
-
export * from './utils.mjs';
|
|
27
|
-
|
|
28
|
-
const {
|
|
29
|
-
HTTP2_HEADER_CONTENT_TYPE,
|
|
30
|
-
} = http2.constants;
|
|
31
|
-
|
|
32
|
-
export default function rekwest(...args) {
|
|
33
|
-
let options = sanitize(...args);
|
|
34
|
-
|
|
35
|
-
if (!options.redirected) {
|
|
36
|
-
options = merge(rekwest.defaults, options);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return transfer(validation(options));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
Reflect.defineProperty(rekwest, 'stream', {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
value(...args) {
|
|
45
|
-
const options = preflight({
|
|
46
|
-
...validation(merge(rekwest.defaults, {
|
|
47
|
-
headers: { [HTTP2_HEADER_CONTENT_TYPE]: APPLICATION_OCTET_STREAM },
|
|
48
|
-
}, sanitize(...args))),
|
|
49
|
-
redirect: requestRedirect.manual,
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const { h2, url } = options;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
import http2 from 'node:http2';
|
|
3
|
+
import https from 'node:https';
|
|
4
|
+
import { requestRedirect } from './constants.mjs';
|
|
5
|
+
import defaults from './defaults.mjs';
|
|
6
|
+
import { APPLICATION_OCTET_STREAM } from './mediatypes.mjs';
|
|
7
|
+
import { preflight } from './preflight.mjs';
|
|
8
|
+
import {
|
|
9
|
+
admix,
|
|
10
|
+
affix,
|
|
11
|
+
merge,
|
|
12
|
+
sanitize,
|
|
13
|
+
transfer,
|
|
14
|
+
validation,
|
|
15
|
+
} from './utils.mjs';
|
|
16
|
+
|
|
17
|
+
export { constants } from 'node:http2';
|
|
18
|
+
|
|
19
|
+
export * from './ackn.mjs';
|
|
20
|
+
export * from './constants.mjs';
|
|
21
|
+
export * from './cookies.mjs';
|
|
22
|
+
export * from './errors.mjs';
|
|
23
|
+
export * from './file.mjs';
|
|
24
|
+
export * from './formdata.mjs';
|
|
25
|
+
export * as mediatypes from './mediatypes.mjs';
|
|
26
|
+
export * from './utils.mjs';
|
|
27
|
+
|
|
28
|
+
const {
|
|
29
|
+
HTTP2_HEADER_CONTENT_TYPE,
|
|
30
|
+
} = http2.constants;
|
|
31
|
+
|
|
32
|
+
export default function rekwest(...args) {
|
|
33
|
+
let options = sanitize(...args);
|
|
34
|
+
|
|
35
|
+
if (!options.redirected) {
|
|
36
|
+
options = merge(rekwest.defaults, options);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return transfer(validation(options));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
Reflect.defineProperty(rekwest, 'stream', {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
value(...args) {
|
|
45
|
+
const options = preflight({
|
|
46
|
+
...validation(merge(rekwest.defaults, {
|
|
47
|
+
headers: { [HTTP2_HEADER_CONTENT_TYPE]: APPLICATION_OCTET_STREAM },
|
|
48
|
+
}, sanitize(...args))),
|
|
49
|
+
redirect: requestRedirect.manual,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const { h2, url } = options;
|
|
53
|
+
let client, req;
|
|
54
|
+
|
|
55
|
+
if (h2) {
|
|
56
|
+
client = http2.connect(url.origin, options);
|
|
57
|
+
req = client.request(options.headers, options);
|
|
58
|
+
} else {
|
|
59
|
+
const { request } = (url.protocol === 'http:' ? http : https);
|
|
60
|
+
|
|
61
|
+
req = request(url, options);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
affix(client, req, options);
|
|
65
|
+
|
|
66
|
+
req.once('response', (res) => {
|
|
67
|
+
let headers;
|
|
68
|
+
|
|
69
|
+
if (h2) {
|
|
70
|
+
headers = res;
|
|
71
|
+
res = req;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
admix(res, headers, options);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return req;
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
Reflect.defineProperty(rekwest, 'defaults', {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
get() { return defaults.stash; },
|
|
84
|
+
set(value) { defaults.stash = merge(defaults.stash, value); },
|
|
85
|
+
});
|
package/src/postflight.mjs
CHANGED
|
@@ -109,6 +109,7 @@ export const postflight = (req, res, options, { reject, resolve }) => {
|
|
|
109
109
|
options.method = HTTP2_METHOD_GET;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
Reflect.set(options, 'h2', false);
|
|
112
113
|
Reflect.set(options, 'redirected', true);
|
|
113
114
|
|
|
114
115
|
if (statusCode === HTTP_STATUS_MOVED_PERMANENTLY && res.headers[HTTP2_HEADER_RETRY_AFTER]) {
|
package/src/preflight.mjs
CHANGED
|
@@ -20,7 +20,7 @@ const {
|
|
|
20
20
|
} = http2.constants;
|
|
21
21
|
|
|
22
22
|
export const preflight = (options) => {
|
|
23
|
-
const { cookies, credentials, h2
|
|
23
|
+
const { cookies, credentials, h2, headers, method, url } = options;
|
|
24
24
|
|
|
25
25
|
if (h2) {
|
|
26
26
|
options.endStream = [
|
|
@@ -52,7 +52,6 @@ export const preflight = (options) => {
|
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
options.h2 ??= h2;
|
|
56
55
|
options.headers = {
|
|
57
56
|
[HTTP2_HEADER_ACCEPT]: `${ APPLICATION_JSON }, ${ TEXT_PLAIN }, ${ WILDCARD }`,
|
|
58
57
|
[HTTP2_HEADER_ACCEPT_ENCODING]: 'br, deflate, deflate-raw, gzip, identity',
|
package/src/utils.mjs
CHANGED
|
@@ -299,14 +299,18 @@ export async function* tap(value) {
|
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
export const transfer = async (options) => {
|
|
302
|
-
const { url } = options;
|
|
302
|
+
const { digest, h2, redirected, thenable, url } = options;
|
|
303
303
|
|
|
304
304
|
if (options.follow === 0) {
|
|
305
305
|
throw new RequestError(`Maximum redirect reached at: ${ url.href }`);
|
|
306
306
|
}
|
|
307
307
|
|
|
308
308
|
if (url.protocol === 'https:') {
|
|
309
|
-
options = await ackn(options)
|
|
309
|
+
options = !h2 ? await ackn(options) : {
|
|
310
|
+
...options,
|
|
311
|
+
createConnection: null,
|
|
312
|
+
protocol: url.protocol,
|
|
313
|
+
};
|
|
310
314
|
} else if (Reflect.has(options, 'alpnProtocol')) {
|
|
311
315
|
[
|
|
312
316
|
'alpnProtocol',
|
|
@@ -323,16 +327,15 @@ export const transfer = async (options) => {
|
|
|
323
327
|
throw ex;
|
|
324
328
|
}
|
|
325
329
|
|
|
326
|
-
const { digest, h2, redirected, thenable } = options;
|
|
327
|
-
const { request } = (url.protocol === 'http:' ? http : https);
|
|
328
|
-
|
|
329
330
|
const promise = new Promise((resolve, reject) => {
|
|
330
331
|
let client, req;
|
|
331
332
|
|
|
332
|
-
if (h2) {
|
|
333
|
+
if (options.h2) {
|
|
333
334
|
client = http2.connect(url.origin, options);
|
|
334
335
|
req = client.request(options.headers, options);
|
|
335
336
|
} else {
|
|
337
|
+
const { request } = (url.protocol === 'http:' ? http : https);
|
|
338
|
+
|
|
336
339
|
req = request(url, options);
|
|
337
340
|
}
|
|
338
341
|
|