rekwest 6.0.1 → 6.1.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 +5 -4
- package/dist/config.js +13 -0
- package/dist/mixin.js +4 -1
- package/dist/transform.js +2 -2
- package/dist/utils.js +16 -12
- package/package.json +8 -8
- package/src/config.mjs +13 -0
- package/src/mixin.mjs +2 -2
- package/src/transform.mjs +2 -2
- package/src/utils.mjs +12 -12
package/README.md
CHANGED
|
@@ -120,6 +120,7 @@ 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
124
|
* `baseURL` **{string | URL}** The base URL to use in cases where `url` is a relative URL
|
|
124
125
|
* `body` **{string | Array | ArrayBuffer | ArrayBufferView | AsyncIterator | Blob | Buffer | DataView | File |
|
|
125
126
|
FormData | Iterator | Object | Readable | ReadableStream | SharedArrayBuffer | URLSearchParams}** The body to send
|
|
@@ -130,12 +131,12 @@ console.log(res.body);
|
|
|
130
131
|
* `cookiesTTL` **{boolean}** `Default: false` Controls enablement of TTL for the cookies cache
|
|
131
132
|
* `credentials` **{include | omit | same-origin}** `Default: same-origin` Controls credentials in case of cross-origin
|
|
132
133
|
redirects
|
|
133
|
-
* `digest` **{boolean}** `Default: true` Controls whether to read the response stream or
|
|
134
|
+
* `digest` **{boolean}** `Default: true` Controls whether to read the response stream or add a mixin
|
|
134
135
|
* `follow` **{number}** `Default: 20` The number of redirects to follow
|
|
135
136
|
* `h2` **{boolean}** `Default: false` Forces the use of HTTP/2 protocol
|
|
136
137
|
* `headers` **{Object}** The headers to add to the request
|
|
137
138
|
* `maxRetryAfter` **{number}** The upper limit of `retry-after` header. If unset, it will use `timeout` value
|
|
138
|
-
* `parse` **{boolean}** `Default: true` Controls whether to parse response body or
|
|
139
|
+
* `parse` **{boolean}** `Default: true` Controls whether to parse response body or return a buffer
|
|
139
140
|
* `redirect` **{error | follow | manual}** `Default: follow` Controls the redirect flows
|
|
140
141
|
* `retry` **{Object}** Represents the retry options
|
|
141
142
|
* `attempts` **{number}** `Default: 0` The number of retry attempts
|
|
@@ -164,10 +165,10 @@ console.log(res.body);
|
|
|
164
165
|
* `bytes` **{AsyncFunction}** Reads the response and returns **Uint8Array**
|
|
165
166
|
* `json` **{AsyncFunction}** Reads the response and returns **Object**
|
|
166
167
|
* `text` **{AsyncFunction}** Reads the response and returns **String**
|
|
167
|
-
* `bodyUsed` **{boolean}** Indicates whether the response
|
|
168
|
+
* `bodyUsed` **{boolean}** Indicates whether the response was read or not
|
|
168
169
|
* `cookies` **{undefined | Cookies}** The cookies sent and received with the response
|
|
169
170
|
* `headers` **{Object}** The headers received with the response
|
|
170
|
-
* `httpVersion` **{string}** Indicates protocol version negotiated with the server
|
|
171
|
+
* `httpVersion` **{string}** Indicates a protocol version negotiated with the server
|
|
171
172
|
* `ok` **{boolean}** Indicates if the response was successful (statusCode: **200-299**)
|
|
172
173
|
* `redirected` **{boolean}** Indicates if the response is the result of a redirect
|
|
173
174
|
* `statusCode` **{number}** Indicates the status code of the response
|
package/dist/config.js
CHANGED
|
@@ -22,6 +22,19 @@ const {
|
|
|
22
22
|
} = _nodeHttp.default.constants;
|
|
23
23
|
const isZstdSupported = exports.isZstdSupported = !!_nodeZlib.default.constants.ZSTD_CLEVEL_DEFAULT;
|
|
24
24
|
const defaults = {
|
|
25
|
+
compression: {
|
|
26
|
+
brotliOptions: {
|
|
27
|
+
params: {
|
|
28
|
+
[_nodeZlib.default.constants.BROTLI_PARAM_QUALITY]: 4
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
zstdOptions: {
|
|
32
|
+
params: {
|
|
33
|
+
[_nodeZlib.default.constants.ZSTD_c_compressionLevel]: 6,
|
|
34
|
+
[_nodeZlib.default.constants.ZSTD_d_windowLogMax]: 0
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
25
38
|
cookiesTTL: false,
|
|
26
39
|
credentials: _constants.requestCredentials.sameOrigin,
|
|
27
40
|
digest: true,
|
package/dist/mixin.js
CHANGED
|
@@ -13,6 +13,7 @@ const {
|
|
|
13
13
|
HTTP2_HEADER_CONTENT_TYPE
|
|
14
14
|
} = _nodeHttp.default.constants;
|
|
15
15
|
const mixin = (res, {
|
|
16
|
+
compression,
|
|
16
17
|
digest = false,
|
|
17
18
|
parse = false
|
|
18
19
|
} = {}) => {
|
|
@@ -73,7 +74,9 @@ const mixin = (res, {
|
|
|
73
74
|
throw new TypeError('Response stream already read');
|
|
74
75
|
}
|
|
75
76
|
let body = [];
|
|
76
|
-
for await (const chunk of (0, _utils.decompress)(this, this.headers[HTTP2_HEADER_CONTENT_ENCODING]
|
|
77
|
+
for await (const chunk of (0, _utils.decompress)(this, this.headers[HTTP2_HEADER_CONTENT_ENCODING], {
|
|
78
|
+
compression
|
|
79
|
+
})) {
|
|
77
80
|
body.push(chunk);
|
|
78
81
|
}
|
|
79
82
|
body = Buffer.concat(body);
|
package/dist/transform.js
CHANGED
|
@@ -58,9 +58,9 @@ const transform = async options => {
|
|
|
58
58
|
const encodings = options.headers[HTTP2_HEADER_CONTENT_ENCODING];
|
|
59
59
|
if (body === Object(body) && (Reflect.has(body, Symbol.asyncIterator) || !Array.isArray(body) && Reflect.has(body, Symbol.iterator))) {
|
|
60
60
|
body = (0, _nodeStream.isReadable)(body) ? (0, _utils.isReadableStream)(body) ? _nodeStream.Readable.fromWeb(body) : body : _nodeStream.Readable.from(body);
|
|
61
|
-
body = encodings ? (0, _utils.compress)(body, encodings) : body;
|
|
61
|
+
body = encodings ? (0, _utils.compress)(body, encodings, options) : body;
|
|
62
62
|
} else if (encodings) {
|
|
63
|
-
body = await (0, _consumers.buffer)((0, _utils.compress)(_nodeStream.Readable.from(body), encodings));
|
|
63
|
+
body = await (0, _consumers.buffer)((0, _utils.compress)(_nodeStream.Readable.from(body), encodings, options));
|
|
64
64
|
}
|
|
65
65
|
Object.assign(options.headers, {
|
|
66
66
|
...headers,
|
package/dist/utils.js
CHANGED
|
@@ -64,20 +64,22 @@ const brandCheck = (value, ctor) => {
|
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
exports.brandCheck = brandCheck;
|
|
67
|
-
const compress = (readable, encodings = ''
|
|
67
|
+
const compress = (readable, encodings = '', {
|
|
68
|
+
compression
|
|
69
|
+
} = {}) => {
|
|
68
70
|
const encoders = [];
|
|
69
71
|
encodings = unwind(encodings);
|
|
70
72
|
for (const encoding of encodings) {
|
|
71
73
|
if (/\bbr\b/i.test(encoding)) {
|
|
72
|
-
encoders.push(_nodeZlib.default.createBrotliCompress());
|
|
74
|
+
encoders.push(_nodeZlib.default.createBrotliCompress(compression?.brotliOptions));
|
|
73
75
|
} else if (/\bdeflate(?!-(?:\w+)?)\b/i.test(encoding)) {
|
|
74
|
-
encoders.push(_nodeZlib.default.createDeflate());
|
|
76
|
+
encoders.push(_nodeZlib.default.createDeflate(compression?.zlibOptions));
|
|
75
77
|
} else if (/\bdeflate-raw\b/i.test(encoding)) {
|
|
76
|
-
encoders.push(_nodeZlib.default.createDeflateRaw());
|
|
78
|
+
encoders.push(_nodeZlib.default.createDeflateRaw(compression?.zlibOptions));
|
|
77
79
|
} else if (/\bgzip\b/i.test(encoding)) {
|
|
78
|
-
encoders.push(_nodeZlib.default.createGzip());
|
|
80
|
+
encoders.push(_nodeZlib.default.createGzip(compression?.zlibOptions));
|
|
79
81
|
} else if (_config.isZstdSupported && /\bzstd\b/i.test(encoding)) {
|
|
80
|
-
encoders.push(_nodeZlib.default.createZstdCompress());
|
|
82
|
+
encoders.push(_nodeZlib.default.createZstdCompress(compression?.zstdOptions));
|
|
81
83
|
} else {
|
|
82
84
|
return readable;
|
|
83
85
|
}
|
|
@@ -93,20 +95,22 @@ const copyWithMerge = (target, ...rest) => {
|
|
|
93
95
|
return merge(target, ...rest);
|
|
94
96
|
};
|
|
95
97
|
exports.copyWithMerge = copyWithMerge;
|
|
96
|
-
const decompress = (readable, encodings = ''
|
|
98
|
+
const decompress = (readable, encodings = '', {
|
|
99
|
+
compression
|
|
100
|
+
} = {}) => {
|
|
97
101
|
const decoders = [];
|
|
98
102
|
encodings = unwind(encodings);
|
|
99
103
|
for (const encoding of encodings) {
|
|
100
104
|
if (/\bbr\b/i.test(encoding)) {
|
|
101
|
-
decoders.push(_nodeZlib.default.createBrotliDecompress());
|
|
105
|
+
decoders.push(_nodeZlib.default.createBrotliDecompress(compression?.brotliOptions));
|
|
102
106
|
} else if (/\bdeflate(?!-(?:\w+)?)\b/i.test(encoding)) {
|
|
103
|
-
decoders.push(_nodeZlib.default.createInflate());
|
|
107
|
+
decoders.push(_nodeZlib.default.createInflate(compression?.zlibOptions));
|
|
104
108
|
} else if (/\bdeflate-raw\b/i.test(encoding)) {
|
|
105
|
-
decoders.push(_nodeZlib.default.createInflateRaw());
|
|
109
|
+
decoders.push(_nodeZlib.default.createInflateRaw(compression?.zlibOptions));
|
|
106
110
|
} else if (/\bgzip\b/i.test(encoding)) {
|
|
107
|
-
decoders.push(_nodeZlib.default.createGunzip());
|
|
111
|
+
decoders.push(_nodeZlib.default.createGunzip(compression?.zlibOptions));
|
|
108
112
|
} else if (_config.isZstdSupported && /\bzstd\b/i.test(encoding)) {
|
|
109
|
-
decoders.push(_nodeZlib.default.createZstdDecompress());
|
|
113
|
+
decoders.push(_nodeZlib.default.createZstdDecompress(compression?.zstdOptions));
|
|
110
114
|
} else {
|
|
111
115
|
return readable;
|
|
112
116
|
}
|
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.28.
|
|
12
|
-
"@babel/core": "^7.28.
|
|
13
|
-
"@babel/eslint-parser": "^7.28.
|
|
14
|
-
"@babel/preset-env": "^7.28.
|
|
11
|
+
"@babel/cli": "^7.28.3",
|
|
12
|
+
"@babel/core": "^7.28.4",
|
|
13
|
+
"@babel/eslint-parser": "^7.28.4",
|
|
14
|
+
"@babel/preset-env": "^7.28.3",
|
|
15
15
|
"c8": "^10.1.3",
|
|
16
|
-
"eslint": "^9.
|
|
17
|
-
"eslint-config-ultra-refined": "^3.
|
|
18
|
-
"mocha": "^11.7.
|
|
16
|
+
"eslint": "^9.35.0",
|
|
17
|
+
"eslint-config-ultra-refined": "^3.8.0",
|
|
18
|
+
"mocha": "^11.7.2"
|
|
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.0
|
|
74
|
+
"version": "6.1.0"
|
|
75
75
|
}
|
package/src/config.mjs
CHANGED
|
@@ -25,6 +25,19 @@ const {
|
|
|
25
25
|
export const isZstdSupported = !!zlib.constants.ZSTD_CLEVEL_DEFAULT;
|
|
26
26
|
|
|
27
27
|
const defaults = {
|
|
28
|
+
compression: {
|
|
29
|
+
brotliOptions: {
|
|
30
|
+
params: {
|
|
31
|
+
[zlib.constants.BROTLI_PARAM_QUALITY]: 4,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
zstdOptions: {
|
|
35
|
+
params: {
|
|
36
|
+
[zlib.constants.ZSTD_c_compressionLevel]: 6,
|
|
37
|
+
[zlib.constants.ZSTD_d_windowLogMax]: 0,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
28
41
|
cookiesTTL: false,
|
|
29
42
|
credentials: requestCredentials.sameOrigin,
|
|
30
43
|
digest: true,
|
package/src/mixin.mjs
CHANGED
|
@@ -10,7 +10,7 @@ const {
|
|
|
10
10
|
HTTP2_HEADER_CONTENT_TYPE,
|
|
11
11
|
} = http2.constants;
|
|
12
12
|
|
|
13
|
-
export const mixin = (res, { digest = false, parse = false } = {}) => {
|
|
13
|
+
export const mixin = (res, { compression, digest = false, parse = false } = {}) => {
|
|
14
14
|
if (!digest) {
|
|
15
15
|
Object.defineProperties(res, {
|
|
16
16
|
arrayBuffer: {
|
|
@@ -73,7 +73,7 @@ export const mixin = (res, { digest = false, parse = false } = {}) => {
|
|
|
73
73
|
|
|
74
74
|
let body = [];
|
|
75
75
|
|
|
76
|
-
for await (const chunk of decompress(this, this.headers[HTTP2_HEADER_CONTENT_ENCODING])) {
|
|
76
|
+
for await (const chunk of decompress(this, this.headers[HTTP2_HEADER_CONTENT_ENCODING], { compression })) {
|
|
77
77
|
body.push(chunk);
|
|
78
78
|
}
|
|
79
79
|
|
package/src/transform.mjs
CHANGED
|
@@ -60,9 +60,9 @@ export const transform = async (options) => {
|
|
|
60
60
|
if (body === Object(body)
|
|
61
61
|
&& (Reflect.has(body, Symbol.asyncIterator) || (!Array.isArray(body) && Reflect.has(body, Symbol.iterator)))) {
|
|
62
62
|
body = isReadable(body) ? (isReadableStream(body) ? Readable.fromWeb(body) : body) : Readable.from(body);
|
|
63
|
-
body = encodings ? compress(body, encodings) : body;
|
|
63
|
+
body = encodings ? compress(body, encodings, options) : body;
|
|
64
64
|
} else if (encodings) {
|
|
65
|
-
body = await buffer(compress(Readable.from(body), encodings));
|
|
65
|
+
body = await buffer(compress(Readable.from(body), encodings, options));
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
Object.assign(options.headers, {
|
package/src/utils.mjs
CHANGED
|
@@ -65,22 +65,22 @@ export const brandCheck = (value, ctor) => {
|
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
-
export const compress = (readable, encodings = '') => {
|
|
68
|
+
export const compress = (readable, encodings = '', { compression } = {}) => {
|
|
69
69
|
const encoders = [];
|
|
70
70
|
|
|
71
71
|
encodings = unwind(encodings);
|
|
72
72
|
|
|
73
73
|
for (const encoding of encodings) {
|
|
74
74
|
if (/\bbr\b/i.test(encoding)) {
|
|
75
|
-
encoders.push(zlib.createBrotliCompress());
|
|
75
|
+
encoders.push(zlib.createBrotliCompress(compression?.brotliOptions));
|
|
76
76
|
} else if (/\bdeflate(?!-(?:\w+)?)\b/i.test(encoding)) {
|
|
77
|
-
encoders.push(zlib.createDeflate());
|
|
77
|
+
encoders.push(zlib.createDeflate(compression?.zlibOptions));
|
|
78
78
|
} else if (/\bdeflate-raw\b/i.test(encoding)) {
|
|
79
|
-
encoders.push(zlib.createDeflateRaw());
|
|
79
|
+
encoders.push(zlib.createDeflateRaw(compression?.zlibOptions));
|
|
80
80
|
} else if (/\bgzip\b/i.test(encoding)) {
|
|
81
|
-
encoders.push(zlib.createGzip());
|
|
81
|
+
encoders.push(zlib.createGzip(compression?.zlibOptions));
|
|
82
82
|
} else if (isZstdSupported && /\bzstd\b/i.test(encoding)) {
|
|
83
|
-
encoders.push(zlib.createZstdCompress());
|
|
83
|
+
encoders.push(zlib.createZstdCompress(compression?.zstdOptions));
|
|
84
84
|
} else {
|
|
85
85
|
return readable;
|
|
86
86
|
}
|
|
@@ -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 = '', { compression } = {}) => {
|
|
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(compression?.brotliOptions));
|
|
109
109
|
} else if (/\bdeflate(?!-(?:\w+)?)\b/i.test(encoding)) {
|
|
110
|
-
decoders.push(zlib.createInflate());
|
|
110
|
+
decoders.push(zlib.createInflate(compression?.zlibOptions));
|
|
111
111
|
} else if (/\bdeflate-raw\b/i.test(encoding)) {
|
|
112
|
-
decoders.push(zlib.createInflateRaw());
|
|
112
|
+
decoders.push(zlib.createInflateRaw(compression?.zlibOptions));
|
|
113
113
|
} else if (/\bgzip\b/i.test(encoding)) {
|
|
114
|
-
decoders.push(zlib.createGunzip());
|
|
114
|
+
decoders.push(zlib.createGunzip(compression?.zlibOptions));
|
|
115
115
|
} else if (isZstdSupported && /\bzstd\b/i.test(encoding)) {
|
|
116
|
-
decoders.push(zlib.createZstdDecompress());
|
|
116
|
+
decoders.push(zlib.createZstdDecompress(compression?.zstdOptions));
|
|
117
117
|
} else {
|
|
118
118
|
return readable;
|
|
119
119
|
}
|