rekwest 7.0.1 → 7.0.3
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/constants.cjs +2 -12
- package/dist/mixin.cjs +3 -1
- package/dist/postflight.cjs +6 -3
- package/dist/preflight.cjs +1 -1
- package/dist/redirects.cjs +0 -3
- package/dist/transfer.cjs +3 -3
- package/package.json +2 -2
- package/src/constants.js +0 -18
- package/src/mixin.js +7 -2
- package/src/postflight.js +7 -3
- package/src/preflight.js +1 -1
- package/src/redirects.js +0 -5
- package/src/transfer.js +3 -3
package/dist/constants.cjs
CHANGED
|
@@ -3,16 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
var _nodeHttp = _interopRequireDefault(require("node:http2"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
const {
|
|
10
|
-
HTTP_STATUS_FOUND,
|
|
11
|
-
HTTP_STATUS_MOVED_PERMANENTLY,
|
|
12
|
-
HTTP_STATUS_PERMANENT_REDIRECT,
|
|
13
|
-
HTTP_STATUS_SEE_OTHER,
|
|
14
|
-
HTTP_STATUS_TEMPORARY_REDIRECT
|
|
15
|
-
} = _nodeHttp.default.constants;
|
|
6
|
+
exports.requestRedirect = exports.requestCredentials = void 0;
|
|
16
7
|
const requestCredentials = exports.requestCredentials = {
|
|
17
8
|
include: 'include',
|
|
18
9
|
omit: 'omit',
|
|
@@ -22,5 +13,4 @@ const requestRedirect = exports.requestRedirect = {
|
|
|
22
13
|
error: 'error',
|
|
23
14
|
follow: 'follow',
|
|
24
15
|
manual: 'manual'
|
|
25
|
-
};
|
|
26
|
-
const requestRedirectCodes = exports.requestRedirectCodes = [HTTP_STATUS_MOVED_PERMANENTLY, HTTP_STATUS_FOUND, HTTP_STATUS_SEE_OTHER, HTTP_STATUS_TEMPORARY_REDIRECT, HTTP_STATUS_PERMANENT_REDIRECT];
|
|
16
|
+
};
|
package/dist/mixin.cjs
CHANGED
|
@@ -91,8 +91,10 @@ const mixin = (res, {
|
|
|
91
91
|
isTextual = mimeType && (mimeType.type === 'text' || mimeType.subtype.match(/\bcsv\b|\bjson\b|\bxml\b|\byaml\b/) || mimeType.essence.match(/\becmascript\b|\bjavascript\b|\bx-www-form-urlencoded\b/));
|
|
92
92
|
}
|
|
93
93
|
if (isTextual) {
|
|
94
|
-
if (/\bjson\b
|
|
94
|
+
if (/\bjson\b/.test(mimeType)) {
|
|
95
95
|
body = JSON.parse(body.toString());
|
|
96
|
+
} else if ((0, _nodeBuffer.isUtf8)(body)) {
|
|
97
|
+
body = body.toString();
|
|
96
98
|
} else {
|
|
97
99
|
const charset = mimeType.params.get('charset')?.toLowerCase() ?? 'utf-8';
|
|
98
100
|
body = new TextDecoder(charset, {
|
package/dist/postflight.cjs
CHANGED
|
@@ -48,9 +48,12 @@ const postflight = (req, res, options, {
|
|
|
48
48
|
enumerable: true,
|
|
49
49
|
value: cookies !== false && _cookies.Cookies.jar.has(url.origin) ? _cookies.Cookies.jar.get(url.origin) : void 0
|
|
50
50
|
});
|
|
51
|
-
const
|
|
52
|
-
if (Object(
|
|
53
|
-
return
|
|
51
|
+
const result = (0, _redirects.redirects)(res, options);
|
|
52
|
+
if (Object(result) === result) {
|
|
53
|
+
return result.then(resolve, reject);
|
|
54
|
+
}
|
|
55
|
+
if (result) {
|
|
56
|
+
return reject((0, _mixin.mixin)(res, options));
|
|
54
57
|
}
|
|
55
58
|
if (res.statusCode >= HTTP_STATUS_BAD_REQUEST) {
|
|
56
59
|
return reject((0, _mixin.mixin)(res, options));
|
package/dist/preflight.cjs
CHANGED
|
@@ -34,8 +34,8 @@ const preflight = options => {
|
|
|
34
34
|
headers = (0, _utils.stripHeaders)(headers, [HTTP2_HEADER_AUTHORITY, HTTP2_HEADER_METHOD, HTTP2_HEADER_PATH, HTTP2_HEADER_SCHEME]);
|
|
35
35
|
}
|
|
36
36
|
if (credentials === _constants.requestCredentials.omit) {
|
|
37
|
+
cookies = false;
|
|
37
38
|
headers = (0, _utils.stripHeaders)(headers, [HTTP2_HEADER_AUTHORIZATION, HTTP2_HEADER_COOKIE]);
|
|
38
|
-
options.cookies = false;
|
|
39
39
|
url.password = url.username = '';
|
|
40
40
|
}
|
|
41
41
|
if (cookies !== false && credentials !== _constants.requestCredentials.omit) {
|
package/dist/redirects.cjs
CHANGED
|
@@ -30,9 +30,6 @@ const redirects = (res, options) => {
|
|
|
30
30
|
url
|
|
31
31
|
} = options;
|
|
32
32
|
if (follow && /3\d{2}/.test(res.statusCode) && res.headers[HTTP2_HEADER_LOCATION]) {
|
|
33
|
-
if (!_constants.requestRedirectCodes.includes(res.statusCode)) {
|
|
34
|
-
return res.emit('error', new RangeError(`Invalid status code: ${res.statusCode}`));
|
|
35
|
-
}
|
|
36
33
|
if (redirect === _constants.requestRedirect.error) {
|
|
37
34
|
return res.emit('error', new _errors.RequestError(`Unexpected redirect, redirect mode is set to '${redirect}'.`));
|
|
38
35
|
}
|
package/dist/transfer.cjs
CHANGED
|
@@ -71,9 +71,9 @@ const transfer = async options => {
|
|
|
71
71
|
}
|
|
72
72
|
return res;
|
|
73
73
|
} catch (ex) {
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
return
|
|
74
|
+
const result = (0, _retries.retries)(ex, options);
|
|
75
|
+
if (result) {
|
|
76
|
+
return result;
|
|
77
77
|
}
|
|
78
78
|
if (digest && !redirected && ex.body) {
|
|
79
79
|
ex.body = await ex.body();
|
package/package.json
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"alpn",
|
|
35
35
|
"backoff",
|
|
36
36
|
"brotli",
|
|
37
|
-
"
|
|
37
|
+
"cookies",
|
|
38
38
|
"deflate",
|
|
39
39
|
"deflate-raw",
|
|
40
40
|
"fetch",
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"test:cover": "c8 --include=src --reporter=lcov --reporter=text npm test"
|
|
73
73
|
},
|
|
74
74
|
"type": "module",
|
|
75
|
-
"version": "7.0.
|
|
75
|
+
"version": "7.0.3"
|
|
76
76
|
}
|
package/src/constants.js
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
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
1
|
export const requestCredentials = {
|
|
12
2
|
include: 'include',
|
|
13
3
|
omit: 'omit',
|
|
@@ -19,11 +9,3 @@ export const requestRedirect = {
|
|
|
19
9
|
follow: 'follow',
|
|
20
10
|
manual: 'manual',
|
|
21
11
|
};
|
|
22
|
-
|
|
23
|
-
export const requestRedirectCodes = [
|
|
24
|
-
HTTP_STATUS_MOVED_PERMANENTLY,
|
|
25
|
-
HTTP_STATUS_FOUND,
|
|
26
|
-
HTTP_STATUS_SEE_OTHER,
|
|
27
|
-
HTTP_STATUS_TEMPORARY_REDIRECT,
|
|
28
|
-
HTTP_STATUS_PERMANENT_REDIRECT,
|
|
29
|
-
];
|
package/src/mixin.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Blob,
|
|
3
|
+
isUtf8,
|
|
4
|
+
} from 'node:buffer';
|
|
2
5
|
import http2 from 'node:http2';
|
|
3
6
|
import { buffer } from 'node:stream/consumers';
|
|
4
7
|
import { MIMEType } from 'node:util';
|
|
@@ -92,8 +95,10 @@ export const mixin = (res, { decodersOptions, digest = false, parse = false } =
|
|
|
92
95
|
}
|
|
93
96
|
|
|
94
97
|
if (isTextual) {
|
|
95
|
-
if (/\bjson\b
|
|
98
|
+
if (/\bjson\b/.test(mimeType)) {
|
|
96
99
|
body = JSON.parse(body.toString());
|
|
100
|
+
} else if (isUtf8(body)) {
|
|
101
|
+
body = body.toString();
|
|
97
102
|
} else {
|
|
98
103
|
const charset = mimeType.params.get('charset')?.toLowerCase() ?? 'utf-8';
|
|
99
104
|
|
package/src/postflight.js
CHANGED
|
@@ -42,10 +42,14 @@ export const postflight = (req, res, options, { reject, resolve }) => {
|
|
|
42
42
|
value: cookies !== false && Cookies.jar.has(url.origin) ? Cookies.jar.get(url.origin) : void 0,
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
const
|
|
45
|
+
const result = redirects(res, options);
|
|
46
46
|
|
|
47
|
-
if (Object(
|
|
48
|
-
return
|
|
47
|
+
if (Object(result) === result) {
|
|
48
|
+
return result.then(resolve, reject);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (result) {
|
|
52
|
+
return reject(mixin(res, options));
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
if (res.statusCode >= HTTP_STATUS_BAD_REQUEST) {
|
package/src/preflight.js
CHANGED
|
@@ -32,11 +32,11 @@ export const preflight = (options) => {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
if (credentials === requestCredentials.omit) {
|
|
35
|
+
cookies = false;
|
|
35
36
|
headers = stripHeaders(headers, [
|
|
36
37
|
HTTP2_HEADER_AUTHORIZATION,
|
|
37
38
|
HTTP2_HEADER_COOKIE,
|
|
38
39
|
]);
|
|
39
|
-
options.cookies = false;
|
|
40
40
|
url.password = url.username = '';
|
|
41
41
|
}
|
|
42
42
|
|
package/src/redirects.js
CHANGED
|
@@ -3,7 +3,6 @@ import { isReadable } from 'node:stream';
|
|
|
3
3
|
import {
|
|
4
4
|
requestCredentials,
|
|
5
5
|
requestRedirect,
|
|
6
|
-
requestRedirectCodes,
|
|
7
6
|
} from './constants.js';
|
|
8
7
|
import { RequestError } from './errors.js';
|
|
9
8
|
import rekwest from './index.js';
|
|
@@ -28,10 +27,6 @@ export const redirects = (res, options) => {
|
|
|
28
27
|
const { credentials, follow, redirect, url } = options;
|
|
29
28
|
|
|
30
29
|
if (follow && /3\d{2}/.test(res.statusCode) && res.headers[HTTP2_HEADER_LOCATION]) {
|
|
31
|
-
if (!requestRedirectCodes.includes(res.statusCode)) {
|
|
32
|
-
return res.emit('error', new RangeError(`Invalid status code: ${ res.statusCode }`));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
30
|
if (redirect === requestRedirect.error) {
|
|
36
31
|
return res.emit('error', new RequestError(`Unexpected redirect, redirect mode is set to '${ redirect }'.`));
|
|
37
32
|
}
|
package/src/transfer.js
CHANGED
|
@@ -73,10 +73,10 @@ export const transfer = async (options) => {
|
|
|
73
73
|
|
|
74
74
|
return res;
|
|
75
75
|
} catch (ex) {
|
|
76
|
-
const
|
|
76
|
+
const result = retries(ex, options);
|
|
77
77
|
|
|
78
|
-
if (
|
|
79
|
-
return
|
|
78
|
+
if (result) {
|
|
79
|
+
return result;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
if (digest && !redirected && ex.body) {
|