rekwest 6.1.0 → 6.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/README.md +4 -1
- package/dist/config.js +2 -2
- package/dist/mixin.js +2 -2
- package/dist/utils.js +6 -6
- package/package.json +7 -7
- package/src/config.mjs +1 -1
- package/src/mixin.mjs +117 -117
- package/src/utils.mjs +6 -6
package/README.md
CHANGED
|
@@ -120,7 +120,8 @@ console.log(res.body);
|
|
|
120
120
|
& [http2.ClientSessionRequestOptions](https://nodejs.org/api/http2.html#clienthttp2sessionrequestheaders-options)
|
|
121
121
|
and [tls.ConnectionOptions](https://nodejs.org/api/tls.html#tlsconnectoptions-callback)
|
|
122
122
|
for HTTP/2 attunes
|
|
123
|
-
* `compression` **{Object}** Configures compression options
|
|
123
|
+
* `compression` **{Object}** Configures compression options, e.g.: `brotliOptions`, `zstdOptions`,
|
|
124
|
+
`zlibOptions`
|
|
124
125
|
* `baseURL` **{string | URL}** The base URL to use in cases where `url` is a relative URL
|
|
125
126
|
* `body` **{string | Array | ArrayBuffer | ArrayBufferView | AsyncIterator | Blob | Buffer | DataView | File |
|
|
126
127
|
FormData | Iterator | Object | Readable | ReadableStream | SharedArrayBuffer | URLSearchParams}** The body to send
|
|
@@ -131,6 +132,8 @@ console.log(res.body);
|
|
|
131
132
|
* `cookiesTTL` **{boolean}** `Default: false` Controls enablement of TTL for the cookies cache
|
|
132
133
|
* `credentials` **{include | omit | same-origin}** `Default: same-origin` Controls credentials in case of cross-origin
|
|
133
134
|
redirects
|
|
135
|
+
* `decompression` **{Object}** Configures decompression options, e.g.: `brotliOptions`, `zstdOptions`,
|
|
136
|
+
`zlibOptions`
|
|
134
137
|
* `digest` **{boolean}** `Default: true` Controls whether to read the response stream or add a mixin
|
|
135
138
|
* `follow` **{number}** `Default: 20` The number of redirects to follow
|
|
136
139
|
* `h2` **{boolean}** `Default: false` Forces the use of HTTP/2 protocol
|
package/dist/config.js
CHANGED
|
@@ -30,13 +30,13 @@ const defaults = {
|
|
|
30
30
|
},
|
|
31
31
|
zstdOptions: {
|
|
32
32
|
params: {
|
|
33
|
-
[_nodeZlib.default.constants.ZSTD_c_compressionLevel]: 6
|
|
34
|
-
[_nodeZlib.default.constants.ZSTD_d_windowLogMax]: 0
|
|
33
|
+
[_nodeZlib.default.constants.ZSTD_c_compressionLevel]: 6
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
36
|
},
|
|
38
37
|
cookiesTTL: false,
|
|
39
38
|
credentials: _constants.requestCredentials.sameOrigin,
|
|
39
|
+
decompression: {},
|
|
40
40
|
digest: true,
|
|
41
41
|
follow: 20,
|
|
42
42
|
h2: false,
|
package/dist/mixin.js
CHANGED
|
@@ -13,7 +13,7 @@ const {
|
|
|
13
13
|
HTTP2_HEADER_CONTENT_TYPE
|
|
14
14
|
} = _nodeHttp.default.constants;
|
|
15
15
|
const mixin = (res, {
|
|
16
|
-
|
|
16
|
+
decompression,
|
|
17
17
|
digest = false,
|
|
18
18
|
parse = false
|
|
19
19
|
} = {}) => {
|
|
@@ -75,7 +75,7 @@ const mixin = (res, {
|
|
|
75
75
|
}
|
|
76
76
|
let body = [];
|
|
77
77
|
for await (const chunk of (0, _utils.decompress)(this, this.headers[HTTP2_HEADER_CONTENT_ENCODING], {
|
|
78
|
-
|
|
78
|
+
decompression
|
|
79
79
|
})) {
|
|
80
80
|
body.push(chunk);
|
|
81
81
|
}
|
package/dist/utils.js
CHANGED
|
@@ -96,21 +96,21 @@ const copyWithMerge = (target, ...rest) => {
|
|
|
96
96
|
};
|
|
97
97
|
exports.copyWithMerge = copyWithMerge;
|
|
98
98
|
const decompress = (readable, encodings = '', {
|
|
99
|
-
|
|
99
|
+
decompression
|
|
100
100
|
} = {}) => {
|
|
101
101
|
const decoders = [];
|
|
102
102
|
encodings = unwind(encodings);
|
|
103
103
|
for (const encoding of encodings) {
|
|
104
104
|
if (/\bbr\b/i.test(encoding)) {
|
|
105
|
-
decoders.push(_nodeZlib.default.createBrotliDecompress(
|
|
105
|
+
decoders.push(_nodeZlib.default.createBrotliDecompress(decompression?.brotliOptions));
|
|
106
106
|
} else if (/\bdeflate(?!-(?:\w+)?)\b/i.test(encoding)) {
|
|
107
|
-
decoders.push(_nodeZlib.default.createInflate(
|
|
107
|
+
decoders.push(_nodeZlib.default.createInflate(decompression?.zlibOptions));
|
|
108
108
|
} else if (/\bdeflate-raw\b/i.test(encoding)) {
|
|
109
|
-
decoders.push(_nodeZlib.default.createInflateRaw(
|
|
109
|
+
decoders.push(_nodeZlib.default.createInflateRaw(decompression?.zlibOptions));
|
|
110
110
|
} else if (/\bgzip\b/i.test(encoding)) {
|
|
111
|
-
decoders.push(_nodeZlib.default.createGunzip(
|
|
111
|
+
decoders.push(_nodeZlib.default.createGunzip(decompression?.zlibOptions));
|
|
112
112
|
} else if (_config.isZstdSupported && /\bzstd\b/i.test(encoding)) {
|
|
113
|
-
decoders.push(_nodeZlib.default.createZstdDecompress(
|
|
113
|
+
decoders.push(_nodeZlib.default.createZstdDecompress(decompression?.zstdOptions));
|
|
114
114
|
} else {
|
|
115
115
|
return readable;
|
|
116
116
|
}
|
package/package.json
CHANGED
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@babel/cli": "^7.28.3",
|
|
12
|
-
"@babel/core": "^7.28.
|
|
13
|
-
"@babel/eslint-parser": "^7.28.
|
|
14
|
-
"@babel/preset-env": "^7.28.
|
|
12
|
+
"@babel/core": "^7.28.5",
|
|
13
|
+
"@babel/eslint-parser": "^7.28.5",
|
|
14
|
+
"@babel/preset-env": "^7.28.5",
|
|
15
15
|
"c8": "^10.1.3",
|
|
16
|
-
"eslint": "^9.
|
|
17
|
-
"eslint-config-ultra-refined": "^3.8.
|
|
18
|
-
"mocha": "^11.7.
|
|
16
|
+
"eslint": "^9.39.2",
|
|
17
|
+
"eslint-config-ultra-refined": "^3.8.4",
|
|
18
|
+
"mocha": "^11.7.5"
|
|
19
19
|
},
|
|
20
20
|
"description": "The robust request library that humanity deserves 🌐",
|
|
21
21
|
"engines": {
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"test:bail": "mocha --bail",
|
|
72
72
|
"test:cover": "c8 --include=src --reporter=lcov --reporter=text npm test"
|
|
73
73
|
},
|
|
74
|
-
"version": "6.1
|
|
74
|
+
"version": "6.2.1"
|
|
75
75
|
}
|
package/src/config.mjs
CHANGED
|
@@ -34,12 +34,12 @@ const defaults = {
|
|
|
34
34
|
zstdOptions: {
|
|
35
35
|
params: {
|
|
36
36
|
[zlib.constants.ZSTD_c_compressionLevel]: 6,
|
|
37
|
-
[zlib.constants.ZSTD_d_windowLogMax]: 0,
|
|
38
37
|
},
|
|
39
38
|
},
|
|
40
39
|
},
|
|
41
40
|
cookiesTTL: false,
|
|
42
41
|
credentials: requestCredentials.sameOrigin,
|
|
42
|
+
decompression: {},
|
|
43
43
|
digest: true,
|
|
44
44
|
follow: 20,
|
|
45
45
|
h2: false,
|
package/src/mixin.mjs
CHANGED
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
import { Blob } from 'node:buffer';
|
|
2
|
-
import http2 from 'node:http2';
|
|
3
|
-
import {
|
|
4
|
-
brandCheck,
|
|
5
|
-
decompress,
|
|
6
|
-
} from './utils.mjs';
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
HTTP2_HEADER_CONTENT_ENCODING,
|
|
10
|
-
HTTP2_HEADER_CONTENT_TYPE,
|
|
11
|
-
} = http2.constants;
|
|
12
|
-
|
|
13
|
-
export const mixin = (res, {
|
|
14
|
-
if (!digest) {
|
|
15
|
-
Object.defineProperties(res, {
|
|
16
|
-
arrayBuffer: {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
value: async function () {
|
|
19
|
-
brandCheck(this, res?.constructor);
|
|
20
|
-
parse &&= false;
|
|
21
|
-
const { buffer, byteLength, byteOffset } = await this.body();
|
|
22
|
-
|
|
23
|
-
return buffer.slice(byteOffset, byteOffset + byteLength);
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
blob: {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
value: async function () {
|
|
29
|
-
brandCheck(this, res?.constructor);
|
|
30
|
-
const val = await this.arrayBuffer();
|
|
31
|
-
|
|
32
|
-
return new Blob([val]);
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
bytes: {
|
|
36
|
-
enumerable: true,
|
|
37
|
-
value: async function () {
|
|
38
|
-
brandCheck(this, res?.constructor);
|
|
39
|
-
|
|
40
|
-
return new Uint8Array(await this.arrayBuffer());
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
json: {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
value: async function () {
|
|
46
|
-
brandCheck(this, res?.constructor);
|
|
47
|
-
const val = await this.text();
|
|
48
|
-
|
|
49
|
-
return JSON.parse(val);
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
text: {
|
|
53
|
-
enumerable: true,
|
|
54
|
-
value: async function () {
|
|
55
|
-
brandCheck(this, res?.constructor);
|
|
56
|
-
const blob = await this.blob();
|
|
57
|
-
|
|
58
|
-
return blob.text();
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return Object.defineProperties(res, {
|
|
65
|
-
body: {
|
|
66
|
-
enumerable: true,
|
|
67
|
-
value: async function () {
|
|
68
|
-
brandCheck(this, res?.constructor);
|
|
69
|
-
|
|
70
|
-
if (this.bodyUsed) {
|
|
71
|
-
throw new TypeError('Response stream already read');
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
let body = [];
|
|
75
|
-
|
|
76
|
-
for await (const chunk of decompress(this, this.headers[HTTP2_HEADER_CONTENT_ENCODING], {
|
|
77
|
-
body.push(chunk);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
body = Buffer.concat(body);
|
|
81
|
-
|
|
82
|
-
if (!body.length && parse) {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (body.length && parse) {
|
|
87
|
-
const contentType = this.headers[HTTP2_HEADER_CONTENT_TYPE] ?? '';
|
|
88
|
-
const charset = contentType.split(';')
|
|
89
|
-
.find((it) => /charset=/i.test(it))
|
|
90
|
-
?.toLowerCase()
|
|
91
|
-
.replace('charset=', '')
|
|
92
|
-
.replace('iso-8859-1', 'latin1')
|
|
93
|
-
.trim() || 'utf-8';
|
|
94
|
-
|
|
95
|
-
if (/\bjson\b/i.test(contentType)) {
|
|
96
|
-
body = JSON.parse(body.toString(charset));
|
|
97
|
-
} else if (/\b(?:text|xml)\b/i.test(contentType)) {
|
|
98
|
-
if (/\b(?:latin1|ucs-2|utf-(?:8|16le))\b/i.test(charset)) {
|
|
99
|
-
body = body.toString(charset);
|
|
100
|
-
} else {
|
|
101
|
-
body = new TextDecoder(charset).decode(body);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return body;
|
|
107
|
-
},
|
|
108
|
-
writable: true,
|
|
109
|
-
},
|
|
110
|
-
bodyUsed: {
|
|
111
|
-
enumerable: true,
|
|
112
|
-
get() {
|
|
113
|
-
return this.readableEnded;
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
};
|
|
1
|
+
import { Blob } from 'node:buffer';
|
|
2
|
+
import http2 from 'node:http2';
|
|
3
|
+
import {
|
|
4
|
+
brandCheck,
|
|
5
|
+
decompress,
|
|
6
|
+
} from './utils.mjs';
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
HTTP2_HEADER_CONTENT_ENCODING,
|
|
10
|
+
HTTP2_HEADER_CONTENT_TYPE,
|
|
11
|
+
} = http2.constants;
|
|
12
|
+
|
|
13
|
+
export const mixin = (res, { decompression, digest = false, parse = false } = {}) => {
|
|
14
|
+
if (!digest) {
|
|
15
|
+
Object.defineProperties(res, {
|
|
16
|
+
arrayBuffer: {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
value: async function () {
|
|
19
|
+
brandCheck(this, res?.constructor);
|
|
20
|
+
parse &&= false;
|
|
21
|
+
const { buffer, byteLength, byteOffset } = await this.body();
|
|
22
|
+
|
|
23
|
+
return buffer.slice(byteOffset, byteOffset + byteLength);
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
blob: {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
value: async function () {
|
|
29
|
+
brandCheck(this, res?.constructor);
|
|
30
|
+
const val = await this.arrayBuffer();
|
|
31
|
+
|
|
32
|
+
return new Blob([val]);
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
bytes: {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
value: async function () {
|
|
38
|
+
brandCheck(this, res?.constructor);
|
|
39
|
+
|
|
40
|
+
return new Uint8Array(await this.arrayBuffer());
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
json: {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
value: async function () {
|
|
46
|
+
brandCheck(this, res?.constructor);
|
|
47
|
+
const val = await this.text();
|
|
48
|
+
|
|
49
|
+
return JSON.parse(val);
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
text: {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
value: async function () {
|
|
55
|
+
brandCheck(this, res?.constructor);
|
|
56
|
+
const blob = await this.blob();
|
|
57
|
+
|
|
58
|
+
return blob.text();
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return Object.defineProperties(res, {
|
|
65
|
+
body: {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
value: async function () {
|
|
68
|
+
brandCheck(this, res?.constructor);
|
|
69
|
+
|
|
70
|
+
if (this.bodyUsed) {
|
|
71
|
+
throw new TypeError('Response stream already read');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let body = [];
|
|
75
|
+
|
|
76
|
+
for await (const chunk of decompress(this, this.headers[HTTP2_HEADER_CONTENT_ENCODING], { decompression })) {
|
|
77
|
+
body.push(chunk);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
body = Buffer.concat(body);
|
|
81
|
+
|
|
82
|
+
if (!body.length && parse) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (body.length && parse) {
|
|
87
|
+
const contentType = this.headers[HTTP2_HEADER_CONTENT_TYPE] ?? '';
|
|
88
|
+
const charset = contentType.split(';')
|
|
89
|
+
.find((it) => /charset=/i.test(it))
|
|
90
|
+
?.toLowerCase()
|
|
91
|
+
.replace('charset=', '')
|
|
92
|
+
.replace('iso-8859-1', 'latin1')
|
|
93
|
+
.trim() || 'utf-8';
|
|
94
|
+
|
|
95
|
+
if (/\bjson\b/i.test(contentType)) {
|
|
96
|
+
body = JSON.parse(body.toString(charset));
|
|
97
|
+
} else if (/\b(?:text|xml)\b/i.test(contentType)) {
|
|
98
|
+
if (/\b(?:latin1|ucs-2|utf-(?:8|16le))\b/i.test(charset)) {
|
|
99
|
+
body = body.toString(charset);
|
|
100
|
+
} else {
|
|
101
|
+
body = new TextDecoder(charset).decode(body);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return body;
|
|
107
|
+
},
|
|
108
|
+
writable: true,
|
|
109
|
+
},
|
|
110
|
+
bodyUsed: {
|
|
111
|
+
enumerable: true,
|
|
112
|
+
get() {
|
|
113
|
+
return this.readableEnded;
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
};
|
package/src/utils.mjs
CHANGED
|
@@ -98,22 +98,22 @@ export const copyWithMerge = (target, ...rest) => {
|
|
|
98
98
|
return merge(target, ...rest);
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
-
export const decompress = (readable, encodings = '', {
|
|
101
|
+
export const decompress = (readable, encodings = '', { decompression } = {}) => {
|
|
102
102
|
const decoders = [];
|
|
103
103
|
|
|
104
104
|
encodings = unwind(encodings);
|
|
105
105
|
|
|
106
106
|
for (const encoding of encodings) {
|
|
107
107
|
if (/\bbr\b/i.test(encoding)) {
|
|
108
|
-
decoders.push(zlib.createBrotliDecompress(
|
|
108
|
+
decoders.push(zlib.createBrotliDecompress(decompression?.brotliOptions));
|
|
109
109
|
} else if (/\bdeflate(?!-(?:\w+)?)\b/i.test(encoding)) {
|
|
110
|
-
decoders.push(zlib.createInflate(
|
|
110
|
+
decoders.push(zlib.createInflate(decompression?.zlibOptions));
|
|
111
111
|
} else if (/\bdeflate-raw\b/i.test(encoding)) {
|
|
112
|
-
decoders.push(zlib.createInflateRaw(
|
|
112
|
+
decoders.push(zlib.createInflateRaw(decompression?.zlibOptions));
|
|
113
113
|
} else if (/\bgzip\b/i.test(encoding)) {
|
|
114
|
-
decoders.push(zlib.createGunzip(
|
|
114
|
+
decoders.push(zlib.createGunzip(decompression?.zlibOptions));
|
|
115
115
|
} else if (isZstdSupported && /\bzstd\b/i.test(encoding)) {
|
|
116
|
-
decoders.push(zlib.createZstdDecompress(
|
|
116
|
+
decoders.push(zlib.createZstdDecompress(decompression?.zstdOptions));
|
|
117
117
|
} else {
|
|
118
118
|
return readable;
|
|
119
119
|
}
|