rekwest 5.0.1 → 5.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/README.md CHANGED
@@ -1,241 +1,241 @@
1
- The robust request library that humanity deserves 🌐
2
- ---
3
- This package provides highly likely functional and **easy-to-use** abstraction atop of
4
- native [http(s).request](https://nodejs.org/api/https.html#httpsrequesturl-options-callback)
5
- and [http2.request](https://nodejs.org/api/http2.html#clienthttp2sessionrequestheaders-options).
6
-
7
- ## Abstract
8
-
9
- * Fetch-alike
10
- * Cool-beans 🫐 config options (with defaults)
11
- * Automatic HTTP/2 support (ALPN negotiation)
12
- * Automatic or opt-in body parse (with non-UTF-8 charset decoding)
13
- * Automatic and simplistic `Cookies` treatment (with built-in **jar** & **ttl**)
14
- * Automatic decompression (with opt-in body compression)
15
- * Built-in streamable `FormData` interface
16
- * Support redirects & retries with fine-grained tune-ups
17
- * Support all legit request body types (include blobs & streams)
18
- * Support both CJS and ESM module systems
19
- * Fully promise-able and pipe-able
20
- * Zero dependencies
21
-
22
- ## Prerequisites
23
-
24
- * Node.js `>= 18.13.0`
25
-
26
- ## Installation
27
-
28
- ```bash
29
- npm install rekwest --save
30
- ```
31
-
32
- ### Usage
33
-
34
- ```javascript
35
- import rekwest, { constants } from 'rekwest';
36
-
37
- const {
38
- HTTP2_HEADER_AUTHORIZATION,
39
- HTTP2_HEADER_CONTENT_ENCODING,
40
- HTTP2_METHOD_POST,
41
- HTTP_STATUS_OK,
42
- } = constants;
43
-
44
- const url = 'https://somewhe.re/somewhat/endpoint';
45
-
46
- const res = await rekwest(url, {
47
- body: { celestial: 'payload' },
48
- headers: {
49
- [HTTP2_HEADER_AUTHORIZATION]: 'Bearer [token]',
50
- [HTTP2_HEADER_CONTENT_ENCODING]: 'br', // enables: body compression
51
- /** [HTTP2_HEADER_CONTENT_TYPE]
52
- * is undue for
53
- * Array/Blob/File/FormData/Object/URLSearchParams body types
54
- * and will be set automatically, with an option to override it here
55
- */
56
- },
57
- method: HTTP2_METHOD_POST,
58
- });
59
-
60
- console.assert(res.statusCode === HTTP_STATUS_OK);
61
- console.info(res.headers);
62
- console.log(res.body);
63
- ```
64
-
65
- ---
66
-
67
- ```javascript
68
- import { Readable } from 'node:stream';
69
- import rekwest, {
70
- constants,
71
- Blob,
72
- File,
73
- FormData,
74
- } from 'rekwest';
75
-
76
- const {
77
- HTTP2_HEADER_AUTHORIZATION,
78
- HTTP2_HEADER_CONTENT_ENCODING,
79
- HTTP2_METHOD_POST,
80
- HTTP_STATUS_OK,
81
- } = constants;
82
-
83
- const blob = new Blob(['bits']);
84
- const file = new File(['bits'], 'file.dab');
85
- const readable = Readable.from('bits');
86
-
87
- const fd = new FormData({
88
- aux: Date.now(), // either [[key, value]] or kv sequenceable
89
- });
90
-
91
- fd.append('celestial', 'payload');
92
- fd.append('blob', blob, 'blob.dab');
93
- fd.append('file', file);
94
- fd.append('readable', readable, 'readable.dab');
95
-
96
- const url = 'https://somewhe.re/somewhat/endpoint';
97
-
98
- const res = await rekwest(url, {
99
- body: fd,
100
- headers: {
101
- [HTTP2_HEADER_AUTHORIZATION]: 'Bearer [token]',
102
- [HTTP2_HEADER_CONTENT_ENCODING]: 'br', // enables: body compression
103
- },
104
- method: HTTP2_METHOD_POST,
105
- });
106
-
107
- console.assert(res.statusCode === HTTP_STATUS_OK);
108
- console.info(res.headers);
109
- console.log(res.body);
110
- ```
111
-
112
- ### API
113
-
114
- #### `rekwest(url[, options])`
115
-
116
- * `url` **{string | URL}** The URL to send the request to
117
- * `options` **{Object}**
118
- Extends [http(s).RequestOptions](https://nodejs.org/api/https.html#httpsrequesturl-options-callback) along with
119
- extra [http2.ClientSessionOptions](https://nodejs.org/api/http2.html#http2connectauthority-options-listener)
120
- & [http2.ClientSessionRequestOptions](https://nodejs.org/api/http2.html#clienthttp2sessionrequestheaders-options)
121
- and [tls.ConnectionOptions](https://nodejs.org/api/tls.html#tlsconnectoptions-callback)
122
- for HTTP/2 attunes
123
- * `baseURL` **{string | URL}** The base URL to use in cases where `url` is a relative URL
124
- * `body` **{string | Array | ArrayBuffer | ArrayBufferView | AsyncIterator | Blob | Buffer | DataView | File |
125
- FormData | Iterator | Object | Readable | ReadableStream | SharedArrayBuffer | URLSearchParams}** The body to send
126
- with the request
127
- * `cookies` **{boolean | Array<[k, v]> | Array<string\> | Cookies | Object | URLSearchParams}** `Default: true` The
128
- cookies to add to
129
- the request
130
- * `cookiesTTL` **{boolean}** `Default: false` Controls enablement of TTL for the cookies cache
131
- * `credentials` **{include | omit | same-origin}** `Default: same-origin` Controls credentials in case of cross-origin
132
- redirects
133
- * `digest` **{boolean}** `Default: true` Controls whether to read the response stream or simply add a mixin
134
- * `follow` **{number}** `Default: 20` The number of redirects to follow
135
- * `h2` **{boolean}** `Default: false` Forces the use of HTTP/2 protocol
136
- * `headers` **{Object}** The headers to add to the request
137
- * `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 simply return a buffer
139
- * `redirect` **{error | follow | manual}** `Default: follow` Controls the redirect flows
140
- * `retry` **{Object}** Represents the retry options
141
- * `attempts` **{number}** `Default: 0` The number of retry attempts
142
- * `backoffStrategy` **{string}** `Default: interval * Math.log(Math.random() * (Math.E * Math.E - Math.E) + Math.E)`
143
- The backoff strategy algorithm that increases logarithmically. To fixate set value to `interval * 1`
144
- * `interval` **{number}** `Default: 1e3` The initial retry interval
145
- * `retryAfter` **{boolean}** `Default: true` Controls `retry-after` header receptiveness
146
- * `statusCodes` **{number[]}** `Default: [429, 503]` The list of status codes to retry on
147
- * `stripTrailingSlash` **{boolean}** `Default: false` Controls whether to strip trailing slash at the end of the URL
148
- * `thenable` **{boolean}** `Default: false` Controls the promise resolutions
149
- * `timeout` **{number}** `Default: 3e5` The number of milliseconds a request can take before termination
150
- * `trimTrailingSlashes` **{boolean}** `Default: false` Controls whether to trim trailing slashes within the URL
151
- * **Returns:** Promise that resolves to
152
- extended [http.IncomingMessage](https://nodejs.org/api/http.html#class-httpincomingmessage)
153
- or [http2.ClientHttp2Stream](https://nodejs.org/api/http2.html#class-clienthttp2stream) which is respectively
154
- readable and duplex streams
155
- * if `digest: true` & `parse: true`
156
- * `body` **{string | Array | Buffer | Object}** The body based on its content type
157
- * if `digest: false`
158
- * `arrayBuffer` **{AsyncFunction}** Reads the response and returns **ArrayBuffer**
159
- * `blob` **{AsyncFunction}** Reads the response and returns **Blob**
160
- * `body` **{AsyncFunction}** Reads the response and returns **Buffer** if `parse: false`
161
- * `json` **{AsyncFunction}** Reads the response and returns **Object**
162
- * `text` **{AsyncFunction}** Reads the response and returns **String**
163
- * `bodyUsed` **{boolean}** Indicates whether the response were read or not
164
- * `cookies` **{undefined | Cookies}** The cookies sent and received with the response
165
- * `headers` **{Object}** The headers received with the response
166
- * `httpVersion` **{string}** Indicates protocol version negotiated with the server
167
- * `ok` **{boolean}** Indicates if the response was successful (statusCode: **200-299**)
168
- * `redirected` **{boolean}** Indicates if the response is the result of a redirect
169
- * `statusCode` **{number}** Indicates the status code of the response
170
- * `trailers` **{undefined | Object}** The trailer headers received with the response
171
-
172
- ---
173
-
174
- #### `rekwest.defaults`
175
-
176
- The object to fulfill with default [options](#rekwesturl-options).
177
-
178
- ---
179
-
180
- #### `rekwest.extend(options)`
181
-
182
- The method to extend default [options](#rekwesturl-options) per instance.
183
-
184
- ```javascript
185
- import rekwest, { constants } from 'rekwest';
186
-
187
- const {
188
- HTTP_STATUS_OK,
189
- } = constants;
190
-
191
- const rk = rekwest.extend({
192
- baseURL: 'https://somewhe.re',
193
- });
194
-
195
- const signal = AbortSignal.timeout(1e4);
196
- const url = '/somewhat/endpoint';
197
-
198
- const res = await rk(url, {
199
- signal,
200
- });
201
-
202
- console.assert(res.statusCode === HTTP_STATUS_OK);
203
- console.info(res.headers);
204
- console.log(res.body);
205
- ```
206
-
207
- ---
208
-
209
- #### `rekwest.stream(url[, options])`
210
-
211
- The method with limited functionality to use with streams and/or pipes.
212
-
213
- * No automata (redirects & retries)
214
- * Pass `h2: true` in options to use HTTP/2 protocol
215
- * Use `ackn({ url: URL })` method in advance to check the available protocols
216
-
217
- ```javascript
218
- import fs from 'node:fs';
219
- import { pipeline } from 'node:stream/promises';
220
- import rekwest, {
221
- ackn,
222
- constants,
223
- } from 'rekwest';
224
-
225
- const {
226
- HTTP2_METHOD_POST,
227
- } = constants;
228
-
229
- const url = new URL('https://somewhe.re/somewhat/endpoint');
230
- const options = await ackn({ url });
231
-
232
- await pipeline(
233
- fs.createReadStream('input.dab'),
234
- rekwest.stream(url, { ...options, method: HTTP2_METHOD_POST }),
235
- fs.createWriteStream('output.dab'),
236
- );
237
- ```
238
-
239
- ---
240
-
241
- For more details, please check tests (coverage: **>97%**) in the repository.
1
+ The robust request library that humanity deserves 🌐
2
+ ---
3
+ This package provides highly likely functional and **easy-to-use** abstraction atop of
4
+ native [http(s).request](https://nodejs.org/api/https.html#httpsrequesturl-options-callback)
5
+ and [http2.request](https://nodejs.org/api/http2.html#clienthttp2sessionrequestheaders-options).
6
+
7
+ ## Abstract
8
+
9
+ * Fetch-alike
10
+ * Cool-beans 🫐 config options (with defaults)
11
+ * Automatic HTTP/2 support (ALPN negotiation)
12
+ * Automatic or opt-in body parse (with non-UTF-8 charset decoding)
13
+ * Automatic and simplistic `Cookies` treatment (with built-in **jar** & **ttl**)
14
+ * Automatic decompression (with opt-in body compression)
15
+ * Built-in streamable `FormData` interface
16
+ * Support redirects & retries with fine-grained tune-ups
17
+ * Support all legit request body types (include blobs & streams)
18
+ * Support both CJS and ESM module systems
19
+ * Fully promise-able and pipe-able
20
+ * Zero dependencies
21
+
22
+ ## Prerequisites
23
+
24
+ * Node.js `>= 18.13.0`
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ npm install rekwest --save
30
+ ```
31
+
32
+ ### Usage
33
+
34
+ ```javascript
35
+ import rekwest, { constants } from 'rekwest';
36
+
37
+ const {
38
+ HTTP2_HEADER_AUTHORIZATION,
39
+ HTTP2_HEADER_CONTENT_ENCODING,
40
+ HTTP2_METHOD_POST,
41
+ HTTP_STATUS_OK,
42
+ } = constants;
43
+
44
+ const url = 'https://somewhe.re/somewhat/endpoint';
45
+
46
+ const res = await rekwest(url, {
47
+ body: { celestial: 'payload' },
48
+ headers: {
49
+ [HTTP2_HEADER_AUTHORIZATION]: 'Bearer [token]',
50
+ [HTTP2_HEADER_CONTENT_ENCODING]: 'br', // enables: body compression
51
+ /** [HTTP2_HEADER_CONTENT_TYPE]
52
+ * is undue for
53
+ * Array/Blob/File/FormData/Object/URLSearchParams body types
54
+ * and will be set automatically, with an option to override it here
55
+ */
56
+ },
57
+ method: HTTP2_METHOD_POST,
58
+ });
59
+
60
+ console.assert(res.statusCode === HTTP_STATUS_OK);
61
+ console.info(res.headers);
62
+ console.log(res.body);
63
+ ```
64
+
65
+ ---
66
+
67
+ ```javascript
68
+ import { Readable } from 'node:stream';
69
+ import rekwest, {
70
+ constants,
71
+ Blob,
72
+ File,
73
+ FormData,
74
+ } from 'rekwest';
75
+
76
+ const {
77
+ HTTP2_HEADER_AUTHORIZATION,
78
+ HTTP2_HEADER_CONTENT_ENCODING,
79
+ HTTP2_METHOD_POST,
80
+ HTTP_STATUS_OK,
81
+ } = constants;
82
+
83
+ const blob = new Blob(['bits']);
84
+ const file = new File(['bits'], 'file.dab');
85
+ const readable = Readable.from('bits');
86
+
87
+ const fd = new FormData({
88
+ aux: Date.now(), // either [[key, value]] or kv sequenceable
89
+ });
90
+
91
+ fd.append('celestial', 'payload');
92
+ fd.append('blob', blob, 'blob.dab');
93
+ fd.append('file', file);
94
+ fd.append('readable', readable, 'readable.dab');
95
+
96
+ const url = 'https://somewhe.re/somewhat/endpoint';
97
+
98
+ const res = await rekwest(url, {
99
+ body: fd,
100
+ headers: {
101
+ [HTTP2_HEADER_AUTHORIZATION]: 'Bearer [token]',
102
+ [HTTP2_HEADER_CONTENT_ENCODING]: 'br', // enables: body compression
103
+ },
104
+ method: HTTP2_METHOD_POST,
105
+ });
106
+
107
+ console.assert(res.statusCode === HTTP_STATUS_OK);
108
+ console.info(res.headers);
109
+ console.log(res.body);
110
+ ```
111
+
112
+ ### API
113
+
114
+ #### `rekwest(url[, options])`
115
+
116
+ * `url` **{string | URL}** The URL to send the request to
117
+ * `options` **{Object}**
118
+ Extends [http(s).RequestOptions](https://nodejs.org/api/https.html#httpsrequesturl-options-callback) along with
119
+ extra [http2.ClientSessionOptions](https://nodejs.org/api/http2.html#http2connectauthority-options-listener)
120
+ & [http2.ClientSessionRequestOptions](https://nodejs.org/api/http2.html#clienthttp2sessionrequestheaders-options)
121
+ and [tls.ConnectionOptions](https://nodejs.org/api/tls.html#tlsconnectoptions-callback)
122
+ for HTTP/2 attunes
123
+ * `baseURL` **{string | URL}** The base URL to use in cases where `url` is a relative URL
124
+ * `body` **{string | Array | ArrayBuffer | ArrayBufferView | AsyncIterator | Blob | Buffer | DataView | File |
125
+ FormData | Iterator | Object | Readable | ReadableStream | SharedArrayBuffer | URLSearchParams}** The body to send
126
+ with the request
127
+ * `cookies` **{boolean | Array<[k, v]> | Array<string\> | Cookies | Object | URLSearchParams}** `Default: true` The
128
+ cookies to add to
129
+ the request
130
+ * `cookiesTTL` **{boolean}** `Default: false` Controls enablement of TTL for the cookies cache
131
+ * `credentials` **{include | omit | same-origin}** `Default: same-origin` Controls credentials in case of cross-origin
132
+ redirects
133
+ * `digest` **{boolean}** `Default: true` Controls whether to read the response stream or simply add a mixin
134
+ * `follow` **{number}** `Default: 20` The number of redirects to follow
135
+ * `h2` **{boolean}** `Default: false` Forces the use of HTTP/2 protocol
136
+ * `headers` **{Object}** The headers to add to the request
137
+ * `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 simply return a buffer
139
+ * `redirect` **{error | follow | manual}** `Default: follow` Controls the redirect flows
140
+ * `retry` **{Object}** Represents the retry options
141
+ * `attempts` **{number}** `Default: 0` The number of retry attempts
142
+ * `backoffStrategy` **{string}** `Default: interval * Math.log(Math.random() * (Math.E * Math.E - Math.E) + Math.E)`
143
+ The backoff strategy algorithm that increases logarithmically. To fixate set value to `interval * 1`
144
+ * `interval` **{number}** `Default: 1e3` The initial retry interval
145
+ * `retryAfter` **{boolean}** `Default: true` Controls `retry-after` header receptiveness
146
+ * `statusCodes` **{number[]}** `Default: [429, 503]` The list of status codes to retry on
147
+ * `stripTrailingSlash` **{boolean}** `Default: false` Controls whether to strip trailing slash at the end of the URL
148
+ * `thenable` **{boolean}** `Default: false` Controls the promise resolutions
149
+ * `timeout` **{number}** `Default: 3e5` The number of milliseconds a request can take before termination
150
+ * `trimTrailingSlashes` **{boolean}** `Default: false` Controls whether to trim trailing slashes within the URL
151
+ * **Returns:** Promise that resolves to
152
+ extended [http.IncomingMessage](https://nodejs.org/api/http.html#class-httpincomingmessage)
153
+ or [http2.ClientHttp2Stream](https://nodejs.org/api/http2.html#class-clienthttp2stream) which is respectively
154
+ readable and duplex streams
155
+ * if `digest: true` & `parse: true`
156
+ * `body` **{string | Array | Buffer | Object}** The body based on its content type
157
+ * if `digest: false`
158
+ * `arrayBuffer` **{AsyncFunction}** Reads the response and returns **ArrayBuffer**
159
+ * `blob` **{AsyncFunction}** Reads the response and returns **Blob**
160
+ * `body` **{AsyncFunction}** Reads the response and returns **Buffer** if `parse: false`
161
+ * `json` **{AsyncFunction}** Reads the response and returns **Object**
162
+ * `text` **{AsyncFunction}** Reads the response and returns **String**
163
+ * `bodyUsed` **{boolean}** Indicates whether the response were read or not
164
+ * `cookies` **{undefined | Cookies}** The cookies sent and received with the response
165
+ * `headers` **{Object}** The headers received with the response
166
+ * `httpVersion` **{string}** Indicates protocol version negotiated with the server
167
+ * `ok` **{boolean}** Indicates if the response was successful (statusCode: **200-299**)
168
+ * `redirected` **{boolean}** Indicates if the response is the result of a redirect
169
+ * `statusCode` **{number}** Indicates the status code of the response
170
+ * `trailers` **{undefined | Object}** The trailer headers received with the response
171
+
172
+ ---
173
+
174
+ #### `rekwest.defaults`
175
+
176
+ The object to fulfill with default [options](#rekwesturl-options).
177
+
178
+ ---
179
+
180
+ #### `rekwest.extend(options)`
181
+
182
+ The method to extend default [options](#rekwesturl-options) per instance.
183
+
184
+ ```javascript
185
+ import rekwest, { constants } from 'rekwest';
186
+
187
+ const {
188
+ HTTP_STATUS_OK,
189
+ } = constants;
190
+
191
+ const rk = rekwest.extend({
192
+ baseURL: 'https://somewhe.re',
193
+ });
194
+
195
+ const signal = AbortSignal.timeout(1e4);
196
+ const url = '/somewhat/endpoint';
197
+
198
+ const res = await rk(url, {
199
+ signal,
200
+ });
201
+
202
+ console.assert(res.statusCode === HTTP_STATUS_OK);
203
+ console.info(res.headers);
204
+ console.log(res.body);
205
+ ```
206
+
207
+ ---
208
+
209
+ #### `rekwest.stream(url[, options])`
210
+
211
+ The method with limited functionality to use with streams and/or pipes.
212
+
213
+ * No automata (redirects & retries)
214
+ * Pass `h2: true` in options to use HTTP/2 protocol
215
+ * Use `ackn({ url: URL })` method in advance to check the available protocols
216
+
217
+ ```javascript
218
+ import fs from 'node:fs';
219
+ import { pipeline } from 'node:stream/promises';
220
+ import rekwest, {
221
+ ackn,
222
+ constants,
223
+ } from 'rekwest';
224
+
225
+ const {
226
+ HTTP2_METHOD_POST,
227
+ } = constants;
228
+
229
+ const url = new URL('https://somewhe.re/somewhat/endpoint');
230
+ const options = await ackn({ url });
231
+
232
+ await pipeline(
233
+ fs.createReadStream('/var/tmp/vent/inlet.xyz'),
234
+ rekwest.stream(url, { ...options, method: HTTP2_METHOD_POST }),
235
+ fs.createWriteStream('/var/tmp/vent/outlet.xyz'),
236
+ );
237
+ ```
238
+
239
+ ---
240
+
241
+ For more details, please check tests (coverage: **>97%**) in the repository.
package/dist/constants.js CHANGED
@@ -13,17 +13,14 @@ const {
13
13
  HTTP_STATUS_SEE_OTHER,
14
14
  HTTP_STATUS_TEMPORARY_REDIRECT
15
15
  } = _nodeHttp.default.constants;
16
- const requestCredentials = {
16
+ const requestCredentials = exports.requestCredentials = {
17
17
  include: 'include',
18
18
  omit: 'omit',
19
19
  sameOrigin: 'same-origin'
20
20
  };
21
- exports.requestCredentials = requestCredentials;
22
- const requestRedirect = {
21
+ const requestRedirect = exports.requestRedirect = {
23
22
  error: 'error',
24
23
  follow: 'follow',
25
24
  manual: 'manual'
26
25
  };
27
- exports.requestRedirect = requestRedirect;
28
- const requestRedirectCodes = [HTTP_STATUS_MOVED_PERMANENTLY, HTTP_STATUS_FOUND, HTTP_STATUS_SEE_OTHER, HTTP_STATUS_TEMPORARY_REDIRECT, HTTP_STATUS_PERMANENT_REDIRECT];
29
- exports.requestRedirectCodes = requestRedirectCodes;
26
+ const requestRedirectCodes = exports.requestRedirectCodes = [HTTP_STATUS_MOVED_PERMANENTLY, HTTP_STATUS_FOUND, HTTP_STATUS_SEE_OTHER, HTTP_STATUS_TEMPORARY_REDIRECT, HTTP_STATUS_PERMANENT_REDIRECT];
package/dist/cookies.js CHANGED
@@ -31,41 +31,45 @@ class Cookies extends URLSearchParams {
31
31
  return [it.split(';').at(0).trim()];
32
32
  }
33
33
  const [cookie, ...attrs] = it.split(';').map(it => it.trim());
34
- const ttl = attrs.reduce((acc, val) => {
34
+ const ttl = {};
35
+ for (const val of attrs) {
35
36
  if (/(?:Expires|Max-Age)=/i.test(val)) {
36
37
  const [key, value] = val.toLowerCase().split('=');
37
- acc[(0, _utils.toCamelCase)(key)] = !Number.isNaN(Number(value)) ? value * 1e3 : Date.parse(value) - Date.now();
38
+ ttl[(0, _utils.toCamelCase)(key)] = !Number.isNaN(Number(value)) ? value * 1e3 : Date.parse(value) - Date.now();
38
39
  }
39
- return acc;
40
- }, {});
40
+ }
41
41
  return [cookie.replace(/\u0022/g, ''), Object.keys(ttl).length ? ttl : null];
42
42
  });
43
43
  }
44
44
  super(Array.isArray(input) ? input.map(it => it.at(0)).join('&') : input);
45
45
  if (Array.isArray(input) && cookiesTTL) {
46
- input.filter(it => it.at(1)).forEach(([cookie, ttl]) => {
47
- cookie = cookie.split('=').at(0);
48
- if (this.#chronometry.has(cookie)) {
49
- clearTimeout(this.#chronometry.get(cookie));
50
- this.#chronometry.delete(cookie);
46
+ for (const [cookie, ttl] of input.filter(it => it.at(1))) {
47
+ const key = cookie.split('=').at(0);
48
+ if (this.#chronometry.has(key)) {
49
+ clearTimeout(this.#chronometry.get(key));
50
+ this.#chronometry.delete(key);
51
51
  }
52
52
  const {
53
53
  expires,
54
54
  maxAge
55
55
  } = ttl;
56
- [maxAge, expires].filter(it => Number.isInteger(it)).some(ms => {
56
+ for (const ms of [maxAge, expires]) {
57
+ if (!Number.isInteger(ms)) {
58
+ continue;
59
+ }
57
60
  const ref = new WeakRef(this);
58
61
  const tid = setTimeout(() => {
59
62
  const ctx = ref.deref();
60
63
  if (ctx) {
61
- ctx.#chronometry.delete(cookie);
62
- ctx.delete(cookie);
64
+ ctx.#chronometry.delete(key);
65
+ ctx.delete(key);
63
66
  }
64
67
  }, Math.max(ms, 0));
65
68
  this.constructor.#register(this, tid);
66
- return this.#chronometry.set(cookie, tid);
67
- });
68
- });
69
+ this.#chronometry.set(key, tid);
70
+ break;
71
+ }
72
+ }
69
73
  }
70
74
  }
71
75
  toString() {
package/dist/defaults.js CHANGED
@@ -41,7 +41,6 @@ const stash = {
41
41
  timeout: 3e5,
42
42
  trimTrailingSlashes: false
43
43
  };
44
- var _default = {
44
+ var _default = exports.default = {
45
45
  stash
46
- };
47
- exports.default = _default;
46
+ };
package/dist/formdata.js CHANGED
@@ -81,7 +81,9 @@ class FormData {
81
81
  if (input.constructor === Object) {
82
82
  input = Object.entries(input);
83
83
  }
84
- input.forEach(([key, value]) => this.append(key, value));
84
+ for (const [key, value] of input) {
85
+ this.append(key, value);
86
+ }
85
87
  }
86
88
  }
87
89
  #ensureArgs(args, expected, method) {
package/dist/index.js CHANGED
@@ -135,8 +135,8 @@ Object.keys(_mixin).forEach(function (key) {
135
135
  }
136
136
  });
137
137
  });
138
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
139
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
138
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
139
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
140
140
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
141
141
  const {
142
142
  HTTP2_HEADER_CONTENT_TYPE
@@ -4,15 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.WILDCARD = exports.TEXT_PLAIN = exports.MULTIPART_FORM_DATA = exports.APPLICATION_OCTET_STREAM = exports.APPLICATION_JSON = exports.APPLICATION_FORM_URLENCODED = void 0;
7
- const APPLICATION_FORM_URLENCODED = 'application/x-www-form-urlencoded';
8
- exports.APPLICATION_FORM_URLENCODED = APPLICATION_FORM_URLENCODED;
9
- const APPLICATION_JSON = 'application/json';
10
- exports.APPLICATION_JSON = APPLICATION_JSON;
11
- const APPLICATION_OCTET_STREAM = 'application/octet-stream';
12
- exports.APPLICATION_OCTET_STREAM = APPLICATION_OCTET_STREAM;
13
- const MULTIPART_FORM_DATA = 'multipart/form-data';
14
- exports.MULTIPART_FORM_DATA = MULTIPART_FORM_DATA;
15
- const TEXT_PLAIN = 'text/plain';
16
- exports.TEXT_PLAIN = TEXT_PLAIN;
17
- const WILDCARD = '*/*';
18
- exports.WILDCARD = WILDCARD;
7
+ const APPLICATION_FORM_URLENCODED = exports.APPLICATION_FORM_URLENCODED = 'application/x-www-form-urlencoded';
8
+ const APPLICATION_JSON = exports.APPLICATION_JSON = 'application/json';
9
+ const APPLICATION_OCTET_STREAM = exports.APPLICATION_OCTET_STREAM = 'application/octet-stream';
10
+ const MULTIPART_FORM_DATA = exports.MULTIPART_FORM_DATA = 'multipart/form-data';
11
+ const TEXT_PLAIN = exports.TEXT_PLAIN = 'text/plain';
12
+ const WILDCARD = exports.WILDCARD = '*/*';
@@ -87,7 +87,9 @@ const postflight = (req, res, options, {
87
87
  return res.emit('error', new _errors.RequestError(`Unable to ${redirect} redirect with streamable body.`));
88
88
  }
89
89
  if ([HTTP_STATUS_MOVED_PERMANENTLY, HTTP_STATUS_FOUND].includes(statusCode) && options.method === HTTP2_METHOD_POST || statusCode === HTTP_STATUS_SEE_OTHER && ![HTTP2_METHOD_GET, HTTP2_METHOD_HEAD].includes(options.method)) {
90
- Object.keys(options.headers).filter(it => /^content-/i.test(it)).forEach(it => Reflect.deleteProperty(options.headers, it));
90
+ for (const it of Object.keys(options.headers).filter(val => /^content-/i.test(val))) {
91
+ Reflect.deleteProperty(options.headers, it);
92
+ }
91
93
  options.body = null;
92
94
  options.method = HTTP2_METHOD_GET;
93
95
  }
package/dist/preflight.js CHANGED
@@ -60,7 +60,9 @@ const preflight = options => {
60
60
  }
61
61
  if (credentials === _constants.requestCredentials.omit) {
62
62
  options.cookies = false;
63
- Object.keys(options.headers ?? {}).filter(it => new RegExp(`^(${HTTP2_HEADER_AUTHORIZATION}|${HTTP2_HEADER_COOKIE})$`, 'i').test(it)).forEach(it => Reflect.deleteProperty(options.headers, it));
63
+ for (const it of Object.keys(options.headers ?? {}).filter(val => new RegExp(`^(${HTTP2_HEADER_AUTHORIZATION}|${HTTP2_HEADER_COOKIE})$`, 'i').test(val))) {
64
+ Reflect.deleteProperty(options.headers, it);
65
+ }
64
66
  url.password = url.username = '';
65
67
  }
66
68
  options.headers = {