rekwest 6.2.1 → 7.0.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 +11 -10
- package/dist/codecs.cjs +55 -0
- package/dist/{config.js → config.cjs} +15 -19
- package/dist/{cookies.js → cookies.cjs} +2 -2
- package/dist/{formdata.js → formdata.cjs} +8 -11
- package/dist/{index.js → index.cjs} +27 -15
- package/dist/{mixin.js → mixin.cjs} +22 -17
- package/dist/postflight.cjs +60 -0
- package/dist/{preflight.js → preflight.cjs} +11 -9
- package/dist/redirects.cjs +63 -0
- package/dist/retries.cjs +57 -0
- package/dist/{transfer.js → transfer.cjs} +13 -40
- package/dist/transform.cjs +105 -0
- package/dist/utils.cjs +140 -0
- package/dist/{validation.js → validation.cjs} +1 -1
- package/package.json +13 -12
- package/src/{ackn.mjs → ackn.js} +33 -33
- package/src/codecs.js +55 -0
- package/src/{config.mjs → config.js} +88 -93
- package/src/{constants.mjs → constants.js} +29 -29
- package/src/{cookies.mjs → cookies.js} +100 -100
- package/src/{formdata.mjs → formdata.js} +8 -14
- package/src/{index.mjs → index.js} +22 -22
- package/src/{mediatypes.mjs → mediatypes.js} +6 -6
- package/src/{mixin.mjs → mixin.js} +25 -26
- package/src/postflight.js +56 -0
- package/src/{preflight.mjs → preflight.js} +100 -91
- package/src/redirects.js +79 -0
- package/src/retries.js +51 -0
- package/src/transfer.js +92 -0
- package/src/transform.js +109 -0
- package/src/utils.js +152 -0
- package/src/{validation.mjs → validation.js} +33 -33
- package/dist/postflight.js +0 -117
- package/dist/transform.js +0 -79
- package/dist/utils.js +0 -188
- package/src/postflight.mjs +0 -136
- package/src/transfer.mjs +0 -121
- package/src/transform.mjs +0 -82
- package/src/utils.mjs +0 -205
- /package/dist/{ackn.js → ackn.cjs} +0 -0
- /package/dist/{constants.js → constants.cjs} +0 -0
- /package/dist/{errors.js → errors.cjs} +0 -0
- /package/dist/{mediatypes.js → mediatypes.cjs} +0 -0
- /package/src/{errors.mjs → errors.js} +0 -0
package/dist/retries.cjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.retries = void 0;
|
|
7
|
+
var _nodeHttp = _interopRequireDefault(require("node:http2"));
|
|
8
|
+
var _nodeStream = require("node:stream");
|
|
9
|
+
var _promises = require("node:timers/promises");
|
|
10
|
+
var _errors = require("./errors.cjs");
|
|
11
|
+
var _index = _interopRequireDefault(require("./index.cjs"));
|
|
12
|
+
var _utils = require("./utils.cjs");
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
const {
|
|
15
|
+
HTTP2_HEADER_RETRY_AFTER,
|
|
16
|
+
HTTP2_METHOD_GET,
|
|
17
|
+
HTTP2_METHOD_HEAD
|
|
18
|
+
} = _nodeHttp.default.constants;
|
|
19
|
+
const retries = (ex, options) => {
|
|
20
|
+
const {
|
|
21
|
+
body,
|
|
22
|
+
maxRetryAfter,
|
|
23
|
+
method,
|
|
24
|
+
retry,
|
|
25
|
+
url
|
|
26
|
+
} = options;
|
|
27
|
+
if (retry?.attempts > 0) {
|
|
28
|
+
if (![HTTP2_METHOD_GET, HTTP2_METHOD_HEAD].includes(method) && (0, _utils.isPipeStream)(body) && !(0, _nodeStream.isReadable)(body)) {
|
|
29
|
+
throw new _errors.RequestError('Request stream already read.', {
|
|
30
|
+
cause: ex
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (retry.errorCodes?.includes(ex.code) || retry.statusCodes?.includes(ex.statusCode)) {
|
|
34
|
+
let {
|
|
35
|
+
interval
|
|
36
|
+
} = retry;
|
|
37
|
+
if (retry.retryAfter && ex.headers?.[HTTP2_HEADER_RETRY_AFTER]) {
|
|
38
|
+
interval = ex.headers[HTTP2_HEADER_RETRY_AFTER];
|
|
39
|
+
interval = Math.abs(Number(interval) * 1e3 || new Date(interval) - Date.now()) || 0;
|
|
40
|
+
if (interval > maxRetryAfter) {
|
|
41
|
+
throw new _errors.RequestError(`Maximum '${HTTP2_HEADER_RETRY_AFTER}' limit exceeded: ${interval} ms.`, {
|
|
42
|
+
cause: ex
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
interval = new Function('interval', `return Math.ceil(${retry.backoffStrategy});`)(interval);
|
|
47
|
+
}
|
|
48
|
+
if (interval < 0) {
|
|
49
|
+
interval = 0;
|
|
50
|
+
}
|
|
51
|
+
retry.attempts--;
|
|
52
|
+
retry.interval = interval;
|
|
53
|
+
return (0, _promises.setTimeout)(interval).then(() => (0, _index.default)(url, options));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
exports.retries = retries;
|
|
@@ -7,18 +7,15 @@ exports.transfer = void 0;
|
|
|
7
7
|
var _nodeHttp = _interopRequireDefault(require("node:http"));
|
|
8
8
|
var _nodeHttp2 = _interopRequireDefault(require("node:http2"));
|
|
9
9
|
var _nodeHttps = _interopRequireDefault(require("node:https"));
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var _transform = require("./transform");
|
|
16
|
-
var _utils = require("./utils");
|
|
10
|
+
var _ackn = require("./ackn.cjs");
|
|
11
|
+
var _errors = require("./errors.cjs");
|
|
12
|
+
var _postflight = require("./postflight.cjs");
|
|
13
|
+
var _preflight = require("./preflight.cjs");
|
|
14
|
+
var _retries = require("./retries.cjs");
|
|
15
|
+
var _transform = require("./transform.cjs");
|
|
16
|
+
var _utils = require("./utils.cjs");
|
|
17
17
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
-
const {
|
|
19
|
-
HTTP2_HEADER_RETRY_AFTER
|
|
20
|
-
} = _nodeHttp2.default.constants;
|
|
21
|
-
const transfer = async (options, overact) => {
|
|
18
|
+
const transfer = async options => {
|
|
22
19
|
const {
|
|
23
20
|
digest,
|
|
24
21
|
redirected,
|
|
@@ -56,7 +53,7 @@ const transfer = async (options, overact) => {
|
|
|
56
53
|
} = url.protocol === 'http:' ? _nodeHttp.default : _nodeHttps.default;
|
|
57
54
|
req = request(url, options);
|
|
58
55
|
}
|
|
59
|
-
(0, _utils.
|
|
56
|
+
(0, _utils.snoop)(client, req, options);
|
|
60
57
|
req.once('aborted', reject);
|
|
61
58
|
req.once('error', reject);
|
|
62
59
|
req.once('frameError', reject);
|
|
@@ -65,7 +62,7 @@ const transfer = async (options, overact) => {
|
|
|
65
62
|
reject,
|
|
66
63
|
resolve
|
|
67
64
|
}));
|
|
68
|
-
(0, _utils.dispatch)(
|
|
65
|
+
(0, _utils.dispatch)(req, options);
|
|
69
66
|
});
|
|
70
67
|
try {
|
|
71
68
|
const res = await promise;
|
|
@@ -74,33 +71,9 @@ const transfer = async (options, overact) => {
|
|
|
74
71
|
}
|
|
75
72
|
return res;
|
|
76
73
|
} catch (ex) {
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
} = options;
|
|
81
|
-
if (retry?.attempts > 0) {
|
|
82
|
-
if (retry.errorCodes?.includes(ex.code) || retry.statusCodes?.includes(ex.statusCode)) {
|
|
83
|
-
let {
|
|
84
|
-
interval
|
|
85
|
-
} = retry;
|
|
86
|
-
if (retry.retryAfter && ex.headers?.[HTTP2_HEADER_RETRY_AFTER]) {
|
|
87
|
-
interval = ex.headers[HTTP2_HEADER_RETRY_AFTER];
|
|
88
|
-
interval = Number(interval) * 1e3 || new Date(interval) - Date.now();
|
|
89
|
-
if (interval > maxRetryAfter) {
|
|
90
|
-
throw (0, _utils.maxRetryAfterError)(interval, {
|
|
91
|
-
cause: ex
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
} else {
|
|
95
|
-
interval = new Function('interval', `return Math.ceil(${retry.backoffStrategy});`)(interval);
|
|
96
|
-
}
|
|
97
|
-
if (interval < 0) {
|
|
98
|
-
interval = 0;
|
|
99
|
-
}
|
|
100
|
-
retry.attempts--;
|
|
101
|
-
retry.interval = interval;
|
|
102
|
-
return (0, _promises.setTimeout)(interval).then(() => overact(url, options));
|
|
103
|
-
}
|
|
74
|
+
const willRetry = (0, _retries.retries)(ex, options);
|
|
75
|
+
if (willRetry) {
|
|
76
|
+
return willRetry;
|
|
104
77
|
}
|
|
105
78
|
if (digest && !redirected && ex.body) {
|
|
106
79
|
ex.body = await ex.body();
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.transform = void 0;
|
|
7
|
+
var _nodeHttp = _interopRequireDefault(require("node:http2"));
|
|
8
|
+
var _nodeStream = require("node:stream");
|
|
9
|
+
var _consumers = require("node:stream/consumers");
|
|
10
|
+
var _nodeUtil = require("node:util");
|
|
11
|
+
var _codecs = require("./codecs.cjs");
|
|
12
|
+
var _formdata = require("./formdata.cjs");
|
|
13
|
+
var _mediatypes = require("./mediatypes.cjs");
|
|
14
|
+
var _utils = require("./utils.cjs");
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
+
const {
|
|
17
|
+
HTTP2_HEADER_CONTENT_ENCODING,
|
|
18
|
+
HTTP2_HEADER_CONTENT_LENGTH,
|
|
19
|
+
HTTP2_HEADER_CONTENT_TYPE
|
|
20
|
+
} = _nodeHttp.default.constants;
|
|
21
|
+
const transform = async options => {
|
|
22
|
+
let {
|
|
23
|
+
body,
|
|
24
|
+
headers
|
|
25
|
+
} = options;
|
|
26
|
+
if (!body) {
|
|
27
|
+
return options;
|
|
28
|
+
}
|
|
29
|
+
if (!Buffer.isBuffer(body)) {
|
|
30
|
+
switch (true) {
|
|
31
|
+
case (0, _utils.isFileLike)(body):
|
|
32
|
+
{
|
|
33
|
+
headers = {
|
|
34
|
+
[HTTP2_HEADER_CONTENT_LENGTH]: body.size,
|
|
35
|
+
[HTTP2_HEADER_CONTENT_TYPE]: body.type || _mediatypes.APPLICATION_OCTET_STREAM
|
|
36
|
+
};
|
|
37
|
+
body = body.stream();
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
case _formdata.FormData.alike(body):
|
|
41
|
+
{
|
|
42
|
+
body = _formdata.FormData.actuate(body);
|
|
43
|
+
headers = {
|
|
44
|
+
[HTTP2_HEADER_CONTENT_TYPE]: body.contentType
|
|
45
|
+
};
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case _nodeUtil.types.isAnyArrayBuffer(body):
|
|
49
|
+
{
|
|
50
|
+
body = Buffer.from(body);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case _nodeUtil.types.isArrayBufferView(body):
|
|
54
|
+
{
|
|
55
|
+
body = Buffer.from(body.buffer, body.byteOffset, body.byteLength);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case Object(body) === body && !Reflect.has(body, Symbol.asyncIterator):
|
|
59
|
+
{
|
|
60
|
+
if (body.constructor === URLSearchParams) {
|
|
61
|
+
headers = {
|
|
62
|
+
[HTTP2_HEADER_CONTENT_TYPE]: _mediatypes.APPLICATION_FORM_URLENCODED
|
|
63
|
+
};
|
|
64
|
+
body = body.toString();
|
|
65
|
+
} else if (!(!Array.isArray(body) && Reflect.has(body, Symbol.iterator))) {
|
|
66
|
+
headers = {
|
|
67
|
+
[HTTP2_HEADER_CONTENT_TYPE]: _mediatypes.APPLICATION_JSON
|
|
68
|
+
};
|
|
69
|
+
body = JSON.stringify(body);
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
default:
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const encodings = options.headers[HTTP2_HEADER_CONTENT_ENCODING];
|
|
78
|
+
if (Object(body) === body && (Reflect.has(body, Symbol.asyncIterator) || !Array.isArray(body) && Reflect.has(body, Symbol.iterator))) {
|
|
79
|
+
body = (0, _nodeStream.isReadable)(body) ? (0, _utils.isReadableStream)(body) ? _nodeStream.Readable.fromWeb(body) : body : _nodeStream.Readable.from(body);
|
|
80
|
+
body = encodings ? (0, _codecs.encode)(body, encodings, options) : body;
|
|
81
|
+
} else if (encodings) {
|
|
82
|
+
body = await (0, _consumers.buffer)((0, _codecs.encode)(_nodeStream.Readable.from(body), encodings, options));
|
|
83
|
+
}
|
|
84
|
+
if (options.bufferBody && Object(body) === body) {
|
|
85
|
+
if ((0, _nodeStream.isReadable)(body)) {
|
|
86
|
+
body = await (0, _consumers.buffer)(body);
|
|
87
|
+
} else if (Reflect.has(body, Symbol.asyncIterator)) {
|
|
88
|
+
body = await (0, _consumers.buffer)(body);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
Object.assign(options.headers, {
|
|
92
|
+
...headers,
|
|
93
|
+
...(!body[Symbol.asyncIterator] && {
|
|
94
|
+
[HTTP2_HEADER_CONTENT_LENGTH]: Buffer.byteLength(body)
|
|
95
|
+
}),
|
|
96
|
+
...(options.headers[HTTP2_HEADER_CONTENT_TYPE] && {
|
|
97
|
+
[HTTP2_HEADER_CONTENT_TYPE]: options.headers[HTTP2_HEADER_CONTENT_TYPE]
|
|
98
|
+
})
|
|
99
|
+
});
|
|
100
|
+
return {
|
|
101
|
+
...options,
|
|
102
|
+
body
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
exports.transform = transform;
|
package/dist/utils.cjs
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.snoop = exports.sameOrigin = exports.normalize = exports.merge = exports.isReadableStream = exports.isPipeStream = exports.isFileLike = exports.dispatch = exports.copyWithMerge = exports.brandCheck = exports.augment = void 0;
|
|
7
|
+
exports.tap = tap;
|
|
8
|
+
exports.unwind = exports.toCamelCase = void 0;
|
|
9
|
+
var _nodeBuffer = require("node:buffer");
|
|
10
|
+
var _nodeHttp = _interopRequireDefault(require("node:http2"));
|
|
11
|
+
var _nodeStream = require("node:stream");
|
|
12
|
+
var _config = _interopRequireDefault(require("./config.cjs"));
|
|
13
|
+
var _errors = require("./errors.cjs");
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
const {
|
|
16
|
+
HTTP2_HEADER_STATUS
|
|
17
|
+
} = _nodeHttp.default.constants;
|
|
18
|
+
const augment = (res, headers, options) => {
|
|
19
|
+
const {
|
|
20
|
+
h2
|
|
21
|
+
} = options;
|
|
22
|
+
if (h2) {
|
|
23
|
+
Reflect.defineProperty(res, 'headers', {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
value: headers
|
|
26
|
+
});
|
|
27
|
+
Reflect.defineProperty(res, 'httpVersion', {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
value: `${h2 + 1}.0`
|
|
30
|
+
});
|
|
31
|
+
Reflect.defineProperty(res, 'statusCode', {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
value: headers[HTTP2_HEADER_STATUS]
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
Reflect.defineProperty(res, 'ok', {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
value: /^2\d{2}$/.test(res.statusCode)
|
|
39
|
+
});
|
|
40
|
+
Reflect.defineProperty(res, 'redirected', {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
value: !!options.redirected
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
exports.augment = augment;
|
|
46
|
+
const brandCheck = (value, ctor) => {
|
|
47
|
+
if (!(value instanceof ctor)) {
|
|
48
|
+
throw new TypeError('Illegal invocation.');
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
exports.brandCheck = brandCheck;
|
|
52
|
+
const copyWithMerge = (target, ...rest) => {
|
|
53
|
+
target = structuredClone(target);
|
|
54
|
+
if (!rest.length) {
|
|
55
|
+
return target;
|
|
56
|
+
}
|
|
57
|
+
return merge(target, ...rest);
|
|
58
|
+
};
|
|
59
|
+
exports.copyWithMerge = copyWithMerge;
|
|
60
|
+
const dispatch = (req, {
|
|
61
|
+
body
|
|
62
|
+
}) => {
|
|
63
|
+
if ((0, _nodeStream.isReadable)(body)) {
|
|
64
|
+
body.pipe(req);
|
|
65
|
+
} else {
|
|
66
|
+
req.end(body);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
exports.dispatch = dispatch;
|
|
70
|
+
const isFileLike = value => {
|
|
71
|
+
return [_nodeBuffer.Blob, _nodeBuffer.File].some(it => value instanceof it);
|
|
72
|
+
};
|
|
73
|
+
exports.isFileLike = isFileLike;
|
|
74
|
+
const isPipeStream = value => {
|
|
75
|
+
return value instanceof _nodeStream.Readable;
|
|
76
|
+
};
|
|
77
|
+
exports.isPipeStream = isPipeStream;
|
|
78
|
+
const isReadableStream = value => {
|
|
79
|
+
return value instanceof ReadableStream;
|
|
80
|
+
};
|
|
81
|
+
exports.isReadableStream = isReadableStream;
|
|
82
|
+
const merge = (target, ...rest) => {
|
|
83
|
+
rest = rest.filter(it => Object(it) === it);
|
|
84
|
+
for (const source of rest) {
|
|
85
|
+
for (const key of Object.getOwnPropertyNames(source)) {
|
|
86
|
+
const sv = source[key];
|
|
87
|
+
const tv = target[key];
|
|
88
|
+
if (Object(sv) === sv && Object(tv) === tv) {
|
|
89
|
+
target[key] = merge(tv, sv);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
target[key] = source[key];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return target;
|
|
96
|
+
};
|
|
97
|
+
exports.merge = merge;
|
|
98
|
+
const normalize = (url, options = {}) => {
|
|
99
|
+
if (!options.redirected) {
|
|
100
|
+
options = copyWithMerge(_config.default.defaults, options);
|
|
101
|
+
}
|
|
102
|
+
if (options.trimTrailingSlashes) {
|
|
103
|
+
url = `${url}`.replace(/(?<!:)\/+/g, '/');
|
|
104
|
+
}
|
|
105
|
+
if (options.stripTrailingSlash) {
|
|
106
|
+
url = `${url}`.replace(/\/$|\/(?=#)|\/(?=\?)/g, '');
|
|
107
|
+
}
|
|
108
|
+
url = new URL(url, options.baseURL);
|
|
109
|
+
return Object.assign(options, {
|
|
110
|
+
url
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
exports.normalize = normalize;
|
|
114
|
+
const sameOrigin = (a, b) => a.protocol === b.protocol && a.hostname === b.hostname && a.port === b.port;
|
|
115
|
+
exports.sameOrigin = sameOrigin;
|
|
116
|
+
const snoop = (client, req, options) => {
|
|
117
|
+
req.once('close', () => client?.close());
|
|
118
|
+
req.once('end', () => client?.close());
|
|
119
|
+
req.once('timeout', () => req.destroy(new _errors.TimeoutError(`Timed out after ${options.timeout} ms.`)));
|
|
120
|
+
req.once('trailers', trailers => {
|
|
121
|
+
Reflect.defineProperty(req, 'trailers', {
|
|
122
|
+
enumerable: true,
|
|
123
|
+
value: trailers
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
exports.snoop = snoop;
|
|
128
|
+
async function* tap(value) {
|
|
129
|
+
if (Reflect.has(value, Symbol.asyncIterator)) {
|
|
130
|
+
yield* value;
|
|
131
|
+
} else if (value.stream) {
|
|
132
|
+
yield* value.stream();
|
|
133
|
+
} else {
|
|
134
|
+
yield await value.arrayBuffer();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const toCamelCase = str => str?.toLowerCase().replace(/\p{Punctuation}.|\p{White_Space}./gu, val => val.replace(/\p{Punctuation}+|\p{White_Space}+/gu, '').toUpperCase());
|
|
138
|
+
exports.toCamelCase = toCamelCase;
|
|
139
|
+
const unwind = encodings => encodings.split(',').map(it => it.toLowerCase().trim());
|
|
140
|
+
exports.unwind = unwind;
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.validation = void 0;
|
|
7
7
|
var _nodeHttp = _interopRequireDefault(require("node:http2"));
|
|
8
|
-
var _constants = require("./constants");
|
|
8
|
+
var _constants = require("./constants.cjs");
|
|
9
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
10
|
const {
|
|
11
11
|
HTTP2_METHOD_GET,
|
package/package.json
CHANGED
|
@@ -7,23 +7,23 @@
|
|
|
7
7
|
"bugs": {
|
|
8
8
|
"url": "https://github.com/bricss/rekwest/issues"
|
|
9
9
|
},
|
|
10
|
+
"description": "The robust request library that humanity deserves 🌐",
|
|
10
11
|
"devDependencies": {
|
|
11
|
-
"@babel/cli": "^7.28.
|
|
12
|
-
"@babel/core": "^7.
|
|
13
|
-
"@babel/eslint-parser": "^7.28.
|
|
14
|
-
"@babel/preset-env": "^7.
|
|
12
|
+
"@babel/cli": "^7.28.6",
|
|
13
|
+
"@babel/core": "^7.29.0",
|
|
14
|
+
"@babel/eslint-parser": "^7.28.6",
|
|
15
|
+
"@babel/preset-env": "^7.29.0",
|
|
15
16
|
"c8": "^10.1.3",
|
|
16
17
|
"eslint": "^9.39.2",
|
|
17
|
-
"eslint-config-ultra-refined": "^3.8.
|
|
18
|
+
"eslint-config-ultra-refined": "^3.8.5",
|
|
18
19
|
"mocha": "^11.7.5"
|
|
19
20
|
},
|
|
20
|
-
"description": "The robust request library that humanity deserves 🌐",
|
|
21
21
|
"engines": {
|
|
22
22
|
"node": ">=20.0.0"
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
|
-
"import": "./src/index.
|
|
26
|
-
"require": "./dist/index.
|
|
25
|
+
"import": "./src/index.js",
|
|
26
|
+
"require": "./dist/index.cjs"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"dist",
|
|
@@ -61,15 +61,16 @@
|
|
|
61
61
|
"url": "git+https://github.com/bricss/rekwest.git"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
|
-
"build": "rm -rf dist && npx babel src -
|
|
64
|
+
"build": "rm -rf dist && npx babel src --out-dir dist --out-file-extension .cjs",
|
|
65
65
|
"cert:gen": "openssl req -days 365 -keyout localhost.key -newkey ec -nodes -pkeyopt ec_paramgen_curve:prime256v1 -subj //SKIP=1/CN=localhost -out localhost.cert -x509",
|
|
66
66
|
"cert:ken": "openssl x509 -in localhost.cert -noout -text",
|
|
67
|
-
"lint": "eslint",
|
|
68
|
-
"prepack": "npm run build && sh
|
|
67
|
+
"lint": "eslint --concurrency=auto",
|
|
68
|
+
"prepack": "npm run build && sh misc.sh && npm run lint",
|
|
69
69
|
"pretest": "rm -rf coverage && npm run cert:gen",
|
|
70
70
|
"test": "mocha",
|
|
71
71
|
"test:bail": "mocha --bail",
|
|
72
72
|
"test:cover": "c8 --include=src --reporter=lcov --reporter=text npm test"
|
|
73
73
|
},
|
|
74
|
-
"
|
|
74
|
+
"type": "module",
|
|
75
|
+
"version": "7.0.0"
|
|
75
76
|
}
|
package/src/{ackn.mjs → ackn.js}
RENAMED
|
@@ -1,33 +1,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?/i.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?/i.test(alpnProtocol),
|
|
27
|
+
protocol: url.protocol,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
socket.on('error', reject);
|
|
32
|
+
socket.on('timeout', reject);
|
|
33
|
+
});
|
package/src/codecs.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { pipeline } from 'node:stream';
|
|
2
|
+
import zlib from 'node:zlib';
|
|
3
|
+
import { isZstdSupported } from './config.js';
|
|
4
|
+
import { unwind } from './utils.js';
|
|
5
|
+
|
|
6
|
+
export const decodeCodecs = {
|
|
7
|
+
br: (opts) => zlib.createBrotliDecompress(opts?.brotli),
|
|
8
|
+
deflate: (opts) => zlib.createInflate(opts?.zlib),
|
|
9
|
+
'deflate-raw': (opts) => zlib.createInflateRaw(opts?.zlib),
|
|
10
|
+
gzip: (opts) => zlib.createGunzip(opts?.zlib),
|
|
11
|
+
zstd: (opts) => isZstdSupported && zlib.createZstdDecompress(opts?.zstd),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const decode = (readable, encodings = '', { decodersOptions } = {}) => {
|
|
15
|
+
const decoders = [];
|
|
16
|
+
|
|
17
|
+
encodings = unwind(encodings).reverse();
|
|
18
|
+
|
|
19
|
+
for (const encoding of encodings) {
|
|
20
|
+
const decoder = decodeCodecs[encoding]?.(decodersOptions);
|
|
21
|
+
|
|
22
|
+
if (!decoder) {
|
|
23
|
+
return readable;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
decoders.push(decoder);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return pipeline(readable, ...decoders, () => void 0);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const encodeCodecs = {
|
|
33
|
+
br: (opts) => zlib.createBrotliCompress(opts?.brotli),
|
|
34
|
+
deflate: (opts) => zlib.createDeflate(opts?.zlib),
|
|
35
|
+
'deflate-raw': (opts) => zlib.createDeflateRaw(opts?.zlib),
|
|
36
|
+
gzip: (opts) => zlib.createGzip(opts?.zlib),
|
|
37
|
+
zstd: (opts) => isZstdSupported && zlib.createZstdCompress(opts?.zstd),
|
|
38
|
+
};
|
|
39
|
+
export const encode = (readable, encodings = '', { encodersOptions } = {}) => {
|
|
40
|
+
const encoders = [];
|
|
41
|
+
|
|
42
|
+
encodings = unwind(encodings);
|
|
43
|
+
|
|
44
|
+
for (const encoding of encodings) {
|
|
45
|
+
const encoder = encodeCodecs[encoding]?.(encodersOptions);
|
|
46
|
+
|
|
47
|
+
if (!encoder) {
|
|
48
|
+
return readable;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
encoders.push(encoder);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return pipeline(readable, ...encoders, () => void 0);
|
|
55
|
+
};
|