rekwest 3.1.1 → 3.3.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/dist/index.js CHANGED
@@ -7,15 +7,15 @@ var _exportNames = {
7
7
  exports.constants = void 0;
8
8
  exports.default = rekwest;
9
9
 
10
- var _http = _interopRequireDefault(require("http"));
10
+ var _nodeHttp = _interopRequireDefault(require("node:http"));
11
11
 
12
- var _http2 = _interopRequireDefault(require("http2"));
12
+ var _nodeHttp2 = _interopRequireWildcard(require("node:http2"));
13
13
 
14
- exports.constants = _http2.constants;
14
+ exports.constants = _nodeHttp2.constants;
15
15
 
16
- var _https = _interopRequireDefault(require("https"));
16
+ var _nodeHttps = _interopRequireDefault(require("node:https"));
17
17
 
18
- var _promises = require("timers/promises");
18
+ var _promises = require("node:timers/promises");
19
19
 
20
20
  var _ackn = require("./ackn.js");
21
21
 
@@ -44,17 +44,17 @@ Object.keys(_errors).forEach(function (key) {
44
44
  exports[key] = _errors[key];
45
45
  });
46
46
 
47
- var _helpers = require("./helpers.js");
47
+ var _mediatypes = require("./mediatypes.js");
48
+
49
+ var _utils = require("./utils.js");
48
50
 
49
- Object.keys(_helpers).forEach(function (key) {
51
+ Object.keys(_utils).forEach(function (key) {
50
52
  if (key === "default" || key === "__esModule") return;
51
53
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
52
- if (key in exports && exports[key] === _helpers[key]) return;
53
- exports[key] = _helpers[key];
54
+ if (key in exports && exports[key] === _utils[key]) return;
55
+ exports[key] = _utils[key];
54
56
  });
55
57
 
56
- var _mediatypes = require("./mediatypes.js");
57
-
58
58
  var _file = require("./file.js");
59
59
 
60
60
  Object.keys(_file).forEach(function (key) {
@@ -73,6 +73,10 @@ Object.keys(_formdata).forEach(function (key) {
73
73
  exports[key] = _formdata[key];
74
74
  });
75
75
 
76
+ 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); }
77
+
78
+ 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; }
79
+
76
80
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
77
81
 
78
82
  const {
@@ -88,7 +92,7 @@ const {
88
92
  HTTP_STATUS_SEE_OTHER,
89
93
  HTTP_STATUS_SERVICE_UNAVAILABLE,
90
94
  HTTP_STATUS_TOO_MANY_REQUESTS
91
- } = _http2.default.constants;
95
+ } = _nodeHttp2.default.constants;
92
96
  const maxRetryAfter = Symbol('maxRetryAfter');
93
97
 
94
98
  const maxRetryAfterError = (interval, options) => new _errors.RequestError(`Maximum '${HTTP2_HEADER_RETRY_AFTER}' limit exceeded: ${interval} ms.`, options);
@@ -116,10 +120,15 @@ let defaults = {
116
120
  };
117
121
 
118
122
  async function rekwest(url, options = {}) {
119
- url = options.url = new URL(url);
123
+ ({
124
+ url
125
+ } = (0, _utils.revise)({
126
+ options,
127
+ url
128
+ }));
120
129
 
121
130
  if (!options.redirected) {
122
- options = (0, _helpers.merge)(rekwest.defaults, options);
131
+ options = (0, _utils.merge)(rekwest.defaults, options);
123
132
  }
124
133
 
125
134
  if (options.body && [HTTP2_METHOD_GET, HTTP2_METHOD_HEAD].includes(options.method)) {
@@ -136,7 +145,7 @@ async function rekwest(url, options = {}) {
136
145
  ['alpnProtocol', 'createConnection', 'h2', 'protocol'].forEach(it => Reflect.deleteProperty(options, it));
137
146
  }
138
147
 
139
- options = (0, _helpers.preflight)(options);
148
+ options = (0, _utils.preflight)(options);
140
149
  const {
141
150
  cookies,
142
151
  digest,
@@ -144,29 +153,26 @@ async function rekwest(url, options = {}) {
144
153
  h2,
145
154
  redirect,
146
155
  redirected,
147
- thenable,
148
- url: {
149
- protocol
150
- }
156
+ thenable
151
157
  } = options;
152
158
  const {
153
159
  request
154
- } = protocol === 'http:' ? _http.default : _https.default;
160
+ } = url.protocol === 'http:' ? _nodeHttp.default : _nodeHttps.default;
155
161
  let {
156
162
  body
157
163
  } = options;
158
164
  const promise = new Promise((resolve, reject) => {
159
165
  let client, req;
160
- body &&= (0, _helpers.transform)(body, options);
166
+ body &&= (0, _utils.transform)(body, options);
161
167
 
162
168
  if (h2) {
163
- client = _http2.default.connect(url.origin, options);
169
+ client = _nodeHttp2.default.connect(url.origin, options);
164
170
  req = client.request(options.headers, options);
165
171
  } else {
166
172
  req = request(url, options);
167
173
  }
168
174
 
169
- (0, _helpers.affix)(client, req, options);
175
+ (0, _utils.affix)(client, req, options);
170
176
  req.once('error', reject);
171
177
  req.once('frameError', reject);
172
178
  req.once('goaway', reject);
@@ -180,7 +186,7 @@ async function rekwest(url, options = {}) {
180
186
  res.once('error', reject);
181
187
  }
182
188
 
183
- (0, _helpers.admix)(res, headers, options);
189
+ (0, _utils.admix)(res, headers, options);
184
190
 
185
191
  if (cookies !== false && res.headers[HTTP2_HEADER_SET_COOKIE]) {
186
192
  if (_cookies.Cookies.jar.has(url.origin)) {
@@ -198,15 +204,15 @@ async function rekwest(url, options = {}) {
198
204
  });
199
205
 
200
206
  if (follow && /^3\d{2}$/.test(res.statusCode) && res.headers[HTTP2_HEADER_LOCATION]) {
201
- if (redirect === _helpers.redirects.error) {
202
- res.emit('error', new _errors.RequestError(`Unexpected redirect, redirect mode is set to '${redirect}'.`));
207
+ if (redirect === _utils.redirects.error) {
208
+ return res.emit('error', new _errors.RequestError(`Unexpected redirect, redirect mode is set to '${redirect}'.`));
203
209
  }
204
210
 
205
- if (redirect === _helpers.redirects.follow) {
211
+ if (redirect === _utils.redirects.follow) {
206
212
  options.url = new URL(res.headers[HTTP2_HEADER_LOCATION], url).href;
207
213
 
208
214
  if (res.statusCode !== HTTP_STATUS_SEE_OTHER && body === Object(body) && body.pipe?.constructor === Function) {
209
- res.emit('error', new _errors.RequestError(`Unable to ${redirect} redirect with body as readable stream.`));
215
+ return res.emit('error', new _errors.RequestError(`Unable to ${redirect} redirect with streamable body.`));
210
216
  }
211
217
 
212
218
  options.follow--;
@@ -224,8 +230,8 @@ async function rekwest(url, options = {}) {
224
230
  interval = Number(interval) * 1000 || new Date(interval) - Date.now();
225
231
 
226
232
  if (interval > options.maxRetryAfter) {
227
- res.emit('error', maxRetryAfterError(interval, {
228
- cause: (0, _helpers.mixin)(res, options)
233
+ return res.emit('error', maxRetryAfterError(interval, {
234
+ cause: (0, _utils.mixin)(res, options)
229
235
  }));
230
236
  }
231
237
 
@@ -237,12 +243,12 @@ async function rekwest(url, options = {}) {
237
243
  }
238
244
 
239
245
  if (res.statusCode >= HTTP_STATUS_BAD_REQUEST) {
240
- return reject((0, _helpers.mixin)(res, options));
246
+ return reject((0, _utils.mixin)(res, options));
241
247
  }
242
248
 
243
- resolve((0, _helpers.mixin)(res, options));
249
+ resolve((0, _utils.mixin)(res, options));
244
250
  });
245
- (0, _helpers.dispatch)(req, { ...options,
251
+ (0, _utils.dispatch)(req, { ...options,
246
252
  body
247
253
  });
248
254
  });
@@ -298,35 +304,37 @@ async function rekwest(url, options = {}) {
298
304
 
299
305
  Reflect.defineProperty(rekwest, 'stream', {
300
306
  enumerable: true,
301
- value: function (url, options = {}) {
302
- options = (0, _helpers.preflight)({
303
- url,
304
- ...(0, _helpers.merge)(rekwest.defaults, {
307
+
308
+ value(url, options = {}) {
309
+ ({
310
+ url
311
+ } = (0, _utils.revise)({
312
+ options,
313
+ url
314
+ }));
315
+ options = (0, _utils.preflight)({ ...(0, _utils.merge)(rekwest.defaults, {
305
316
  headers: {
306
317
  [HTTP2_HEADER_CONTENT_TYPE]: _mediatypes.APPLICATION_OCTET_STREAM
307
318
  }
308
319
  }, options),
309
- redirect: _helpers.redirects.manual
320
+ redirect: _utils.redirects.manual
310
321
  });
311
322
  const {
312
- h2,
313
- url: {
314
- protocol
315
- }
323
+ h2
316
324
  } = options;
317
325
  const {
318
326
  request
319
- } = protocol === 'http:' ? _http.default : _https.default;
327
+ } = url.protocol === 'http:' ? _nodeHttp.default : _nodeHttps.default;
320
328
  let client, req;
321
329
 
322
330
  if (h2) {
323
- client = _http2.default.connect(url.origin, options);
331
+ client = _nodeHttp2.default.connect(url.origin, options);
324
332
  req = client.request(options.headers, options);
325
333
  } else {
326
- req = request(options.url, options);
334
+ req = request(url, options);
327
335
  }
328
336
 
329
- (0, _helpers.affix)(client, req, options);
337
+ (0, _utils.affix)(client, req, options);
330
338
  req.once('response', res => {
331
339
  let headers;
332
340
 
@@ -335,10 +343,11 @@ Reflect.defineProperty(rekwest, 'stream', {
335
343
  res = req;
336
344
  }
337
345
 
338
- (0, _helpers.admix)(res, headers, options);
346
+ (0, _utils.admix)(res, headers, options);
339
347
  });
340
348
  return req;
341
349
  }
350
+
342
351
  });
343
352
  Reflect.defineProperty(rekwest, 'defaults', {
344
353
  enumerable: true,
@@ -348,7 +357,7 @@ Reflect.defineProperty(rekwest, 'defaults', {
348
357
  },
349
358
 
350
359
  set(value) {
351
- defaults = (0, _helpers.merge)(defaults, value);
360
+ defaults = (0, _utils.merge)(defaults, value);
352
361
  }
353
362
 
354
363
  });
@@ -1,19 +1,19 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.redirects = exports.preflight = exports.mixin = exports.merge = exports.dispatch = exports.decompress = exports.compress = exports.affix = exports.admix = void 0;
4
+ exports.revise = exports.redirects = exports.preflight = exports.mixin = exports.merge = exports.dispatch = exports.decompress = exports.compress = exports.collate = exports.affix = exports.admix = void 0;
5
5
  exports.tap = tap;
6
6
  exports.transform = void 0;
7
7
 
8
- var _buffer = require("buffer");
8
+ var _nodeBuffer = require("node:buffer");
9
9
 
10
- var _http = _interopRequireDefault(require("http2"));
10
+ var _nodeHttp = _interopRequireDefault(require("node:http2"));
11
11
 
12
- var _stream = require("stream");
12
+ var _nodeStream = require("node:stream");
13
13
 
14
- var _util = require("util");
14
+ var _nodeUtil = require("node:util");
15
15
 
16
- var _zlib = _interopRequireDefault(require("zlib"));
16
+ var _nodeZlib = _interopRequireDefault(require("node:zlib"));
17
17
 
18
18
  var _cookies = require("./cookies.js");
19
19
 
@@ -41,13 +41,13 @@ const {
41
41
  HTTP2_HEADER_STATUS,
42
42
  HTTP2_METHOD_GET,
43
43
  HTTP2_METHOD_HEAD
44
- } = _http.default.constants;
45
- const brotliCompress = (0, _util.promisify)(_zlib.default.brotliCompress);
46
- const brotliDecompress = (0, _util.promisify)(_zlib.default.brotliDecompress);
47
- const gzip = (0, _util.promisify)(_zlib.default.gzip);
48
- const gunzip = (0, _util.promisify)(_zlib.default.gunzip);
49
- const deflate = (0, _util.promisify)(_zlib.default.deflate);
50
- const inflate = (0, _util.promisify)(_zlib.default.inflate);
44
+ } = _nodeHttp.default.constants;
45
+ const brotliCompress = (0, _nodeUtil.promisify)(_nodeZlib.default.brotliCompress);
46
+ const brotliDecompress = (0, _nodeUtil.promisify)(_nodeZlib.default.brotliDecompress);
47
+ const gzip = (0, _nodeUtil.promisify)(_nodeZlib.default.gzip);
48
+ const gunzip = (0, _nodeUtil.promisify)(_nodeZlib.default.gunzip);
49
+ const deflate = (0, _nodeUtil.promisify)(_nodeZlib.default.deflate);
50
+ const inflate = (0, _nodeUtil.promisify)(_nodeZlib.default.inflate);
51
51
 
52
52
  const admix = (res, headers, options) => {
53
53
  const {
@@ -94,14 +94,22 @@ const affix = (client, req, options) => {
94
94
 
95
95
  exports.affix = affix;
96
96
 
97
+ const collate = (entity, primordial) => {
98
+ if (entity?.constructor !== primordial) {
99
+ throw new TypeError('Illegal invocation');
100
+ }
101
+ };
102
+
103
+ exports.collate = collate;
104
+
97
105
  const compress = (buf, encoding, {
98
106
  async = false
99
107
  } = {}) => {
100
108
  encoding &&= encoding.match(/(?<encoding>\bbr\b|\bdeflate\b|\bgzip\b)/i)?.groups.encoding.toLowerCase();
101
109
  const compressor = {
102
- br: async ? brotliCompress : _zlib.default.brotliCompressSync,
103
- deflate: async ? deflate : _zlib.default.deflateSync,
104
- gzip: async ? gzip : _zlib.default.gzipSync
110
+ br: async ? brotliCompress : _nodeZlib.default.brotliCompressSync,
111
+ deflate: async ? deflate : _nodeZlib.default.deflateSync,
112
+ gzip: async ? gzip : _nodeZlib.default.gzipSync
105
113
  }[encoding];
106
114
  return compressor?.(buf) ?? (async ? Promise.resolve(buf) : buf);
107
115
  };
@@ -113,9 +121,9 @@ const decompress = (buf, encoding, {
113
121
  } = {}) => {
114
122
  encoding &&= encoding.match(/(?<encoding>\bbr\b|\bdeflate\b|\bgzip\b)/i)?.groups.encoding.toLowerCase();
115
123
  const decompressor = {
116
- br: async ? brotliDecompress : _zlib.default.brotliDecompressSync,
117
- deflate: async ? inflate : _zlib.default.inflateSync,
118
- gzip: async ? gunzip : _zlib.default.gunzipSync
124
+ br: async ? brotliDecompress : _nodeZlib.default.brotliDecompressSync,
125
+ deflate: async ? inflate : _nodeZlib.default.inflateSync,
126
+ gzip: async ? gunzip : _nodeZlib.default.gunzipSync
119
127
  }[encoding];
120
128
  return decompressor?.(buf) ?? (async ? Promise.resolve(buf) : buf);
121
129
  };
@@ -128,14 +136,14 @@ const dispatch = (req, {
128
136
  }) => {
129
137
  if (body === Object(body) && !Buffer.isBuffer(body)) {
130
138
  if (body.pipe?.constructor !== Function && (Reflect.has(body, Symbol.asyncIterator) || Reflect.has(body, Symbol.iterator))) {
131
- body = _stream.Readable.from(body);
139
+ body = _nodeStream.Readable.from(body);
132
140
  }
133
141
 
134
142
  const compressor = {
135
- br: _zlib.default.createBrotliCompress,
136
- deflate: _zlib.default.createDeflate,
137
- gzip: _zlib.default.createGzip
138
- }[headers[HTTP2_HEADER_CONTENT_ENCODING]] ?? _stream.PassThrough;
143
+ br: _nodeZlib.default.createBrotliCompress,
144
+ deflate: _nodeZlib.default.createDeflate,
145
+ gzip: _nodeZlib.default.createGzip
146
+ }[headers[HTTP2_HEADER_CONTENT_ENCODING]] ?? _nodeStream.PassThrough;
139
147
  body.pipe(compressor()).pipe(req);
140
148
  } else {
141
149
  req.end(body);
@@ -179,7 +187,9 @@ const mixin = (res, {
179
187
  Object.defineProperties(res, {
180
188
  arrayBuffer: {
181
189
  enumerable: true,
182
- value: function () {
190
+
191
+ value() {
192
+ collate(this, res?.constructor);
183
193
  parse &&= false;
184
194
  return this.body().then(({
185
195
  buffer,
@@ -187,24 +197,34 @@ const mixin = (res, {
187
197
  byteOffset
188
198
  }) => buffer.slice(byteOffset, byteOffset + byteLength));
189
199
  }
200
+
190
201
  },
191
202
  blob: {
192
203
  enumerable: true,
193
- value: function () {
194
- return this.arrayBuffer().then(res => new _buffer.Blob([res]));
204
+
205
+ value() {
206
+ collate(this, res?.constructor);
207
+ return this.arrayBuffer().then(res => new _nodeBuffer.Blob([res]));
195
208
  }
209
+
196
210
  },
197
211
  json: {
198
212
  enumerable: true,
199
- value: function () {
213
+
214
+ value() {
215
+ collate(this, res?.constructor);
200
216
  return this.text().then(res => JSON.parse(res));
201
217
  }
218
+
202
219
  },
203
220
  text: {
204
221
  enumerable: true,
205
- value: function () {
222
+
223
+ value() {
224
+ collate(this, res?.constructor);
206
225
  return this.blob().then(blob => blob.text());
207
226
  }
227
+
208
228
  }
209
229
  });
210
230
  }
@@ -213,8 +233,10 @@ const mixin = (res, {
213
233
  body: {
214
234
  enumerable: true,
215
235
  value: async function () {
236
+ collate(this, res?.constructor);
237
+
216
238
  if (this.bodyUsed) {
217
- throw new TypeError('Response stream already read.');
239
+ throw new TypeError('Response stream already read');
218
240
  }
219
241
 
220
242
  let spool = [];
@@ -252,9 +274,11 @@ const mixin = (res, {
252
274
  },
253
275
  bodyUsed: {
254
276
  enumerable: true,
255
- get: function () {
277
+
278
+ get() {
256
279
  return this.readableEnded;
257
280
  }
281
+
258
282
  }
259
283
  });
260
284
  };
@@ -262,13 +286,13 @@ const mixin = (res, {
262
286
  exports.mixin = mixin;
263
287
 
264
288
  const preflight = options => {
265
- const url = options.url = new URL(options.url);
266
289
  const {
267
290
  cookies,
268
291
  h2 = false,
269
- method = HTTP2_METHOD_GET,
270
292
  headers,
271
- redirected
293
+ method = HTTP2_METHOD_GET,
294
+ redirected,
295
+ url
272
296
  } = options;
273
297
 
274
298
  if (h2) {
@@ -333,6 +357,22 @@ const redirects = {
333
357
  };
334
358
  exports.redirects = redirects;
335
359
 
360
+ const revise = ({
361
+ url,
362
+ options
363
+ }) => {
364
+ if (options.trimTrailingSlashes) {
365
+ url = `${url}`.replace(/(?<!:)\/+/gi, '/');
366
+ }
367
+
368
+ url = new URL(url);
369
+ return Object.assign(options, {
370
+ url
371
+ });
372
+ };
373
+
374
+ exports.revise = revise;
375
+
336
376
  async function* tap(value) {
337
377
  if (Reflect.has(value, Symbol.asyncIterator)) {
338
378
  yield* value;
@@ -346,9 +386,9 @@ async function* tap(value) {
346
386
  const transform = (body, options) => {
347
387
  let headers = {};
348
388
 
349
- if (_util.types.isAnyArrayBuffer(body) && !Buffer.isBuffer(body)) {
389
+ if (_nodeUtil.types.isAnyArrayBuffer(body) && !Buffer.isBuffer(body)) {
350
390
  body = Buffer.from(body);
351
- } else if (_util.types.isArrayBufferView(body) && !Buffer.isBuffer(body)) {
391
+ } else if (_nodeUtil.types.isArrayBufferView(body) && !Buffer.isBuffer(body)) {
352
392
  body = Buffer.from(body.buffer, body.byteOffset, body.byteLength);
353
393
  }
354
394
 
@@ -357,7 +397,7 @@ const transform = (body, options) => {
357
397
  [HTTP2_HEADER_CONTENT_LENGTH]: body.size,
358
398
  [HTTP2_HEADER_CONTENT_TYPE]: body.type || _mediatypes.APPLICATION_OCTET_STREAM
359
399
  };
360
- body = body.stream?.() ?? _stream.Readable.from(tap(body));
400
+ body = body.stream?.() ?? _nodeStream.Readable.from(tap(body));
361
401
  } else if (_formdata.FormData.alike(body)) {
362
402
  body = _formdata.FormData.actuate(body);
363
403
  headers = {
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.17.6",
12
- "@babel/core": "^7.17.5",
11
+ "@babel/cli": "^7.17.10",
12
+ "@babel/core": "^7.17.10",
13
13
  "@babel/eslint-parser": "^7.17.0",
14
- "@babel/preset-env": "^7.16.11",
15
- "c8": "^7.11.0",
16
- "eslint": "^8.10.0",
17
- "eslint-config-ultra-refined": "^2.4.1",
18
- "mocha": "^9.2.1"
14
+ "@babel/preset-env": "^7.17.10",
15
+ "c8": "^7.11.2",
16
+ "eslint": "^8.15.0",
17
+ "eslint-config-ultra-refined": "^2.5.0",
18
+ "mocha": "^10.0.0"
19
19
  },
20
20
  "description": "The robust request library that humanity deserves 🌐",
21
21
  "engines": {
@@ -31,6 +31,9 @@
31
31
  ],
32
32
  "homepage": "https://github.com/bricss/rekwest#readme",
33
33
  "keywords": [
34
+ "backoff",
35
+ "compression",
36
+ "cookie",
34
37
  "fetch",
35
38
  "fetch-alike",
36
39
  "formdata",
@@ -40,7 +43,9 @@
40
43
  "h2c",
41
44
  "http2",
42
45
  "multipart",
43
- "request"
46
+ "request",
47
+ "redirect",
48
+ "retry"
44
49
  ],
45
50
  "license": "MIT",
46
51
  "main": "./dist/index.js",
@@ -60,5 +65,5 @@
60
65
  "test:bail": "mocha --bail",
61
66
  "test:cover": "c8 --include=src --reporter=lcov --reporter=text npm test"
62
67
  },
63
- "version": "3.1.1"
68
+ "version": "3.3.1"
64
69
  }
package/src/ackn.mjs CHANGED
@@ -1,33 +1,33 @@
1
- import { connect } from '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?/.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?/.test(alpnProtocol),
27
+ protocol: url.protocol,
28
+ });
29
+ });
30
+
31
+ socket.on('error', reject);
32
+ socket.on('timeout', reject);
33
+ });
package/src/cookies.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import { collate } from './utils.mjs';
2
+
1
3
  export class Cookies extends URLSearchParams {
2
4
 
3
5
  static jar = new Map();
@@ -18,6 +20,8 @@ export class Cookies extends URLSearchParams {
18
20
  }
19
21
 
20
22
  toString() {
23
+ collate(this, Cookies);
24
+
21
25
  return super.toString().split('&').join('; ').trim();
22
26
  }
23
27
 
package/src/file.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { Blob } from 'buffer';
1
+ import { Blob } from 'node:buffer';
2
2
 
3
- export { Blob } from 'buffer';
3
+ export { Blob } from 'node:buffer';
4
4
 
5
5
  export class File extends Blob {
6
6