rekwest 7.2.5 → 7.2.7

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
@@ -22,7 +22,7 @@ and [http2.request](https://nodejs.org/api/http2.html#clienthttp2sessionrequesth
22
22
 
23
23
  ## Prerequisites
24
24
 
25
- * Node.js `>= 20.0.0`
25
+ * Node.js `>=20.0.0`
26
26
 
27
27
  ## Installation
28
28
 
@@ -69,8 +69,6 @@ console.log(res.body);
69
69
  import { Readable } from 'node:stream';
70
70
  import rekwest, {
71
71
  constants,
72
- Blob,
73
- File,
74
72
  FormData,
75
73
  } from 'rekwest';
76
74
 
package/dist/ackn.cjs CHANGED
@@ -5,10 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.ackn = void 0;
7
7
  var _nodeTls = require("node:tls");
8
- const ackn = options => new Promise((resolve, reject) => {
9
- const {
10
- url
11
- } = options;
8
+ const ackn = (options = {}) => new Promise((resolve, reject) => {
9
+ const url = new URL(options.url);
12
10
  const socket = (0, _nodeTls.connect)({
13
11
  ...options,
14
12
  ALPNProtocols: ['h2', 'http/1.1'],
package/dist/config.cjs CHANGED
@@ -13,6 +13,7 @@ const isZstdSupported = exports.isZstdSupported = !!_nodeZlib.default.constants.
13
13
  const {
14
14
  HTTP2_HEADER_ACCEPT,
15
15
  HTTP2_HEADER_ACCEPT_ENCODING,
16
+ HTTP2_HEADER_USER_AGENT,
16
17
  HTTP2_METHOD_GET,
17
18
  HTTP_STATUS_BAD_GATEWAY,
18
19
  HTTP_STATUS_GATEWAY_TIMEOUT,
@@ -44,7 +45,8 @@ const defaults = {
44
45
  h2: false,
45
46
  headers: {
46
47
  [HTTP2_HEADER_ACCEPT]: `${_mediatypes.APPLICATION_JSON}, ${_mediatypes.TEXT_PLAIN}, ${_mediatypes.WILDCARD}`,
47
- [HTTP2_HEADER_ACCEPT_ENCODING]: `br,${isZstdSupported ? ' zstd, ' : ' '}gzip, deflate, deflate-raw`
48
+ [HTTP2_HEADER_ACCEPT_ENCODING]: `br,${isZstdSupported ? ' zstd, ' : ' '}gzip, deflate, deflate-raw`,
49
+ [HTTP2_HEADER_USER_AGENT]: `node/${process.versions.node} ${process.platform}/${process.arch}`
48
50
  },
49
51
  method: HTTP2_METHOD_GET,
50
52
  parse: true,
package/dist/cookies.cjs CHANGED
@@ -5,14 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.splitCookie = exports.maxCookieSize = exports.maxCookieLifetimeCap = exports.isValidCookie = exports.illegalCookieChars = exports.cookieRex = exports.cookiePairRex = exports.Cookies = void 0;
7
7
  var _utils = require("./utils.cjs");
8
- const cookieRex = exports.cookieRex = /^[\w-]+=(?:"[^"]*"|[^\p{Control};]*)(?:;\s*(?:[\w-]+=(?:"[^"]*"|[^\p{Control};]*)|[\w-]+))*$/u;
9
- const cookiePairRex = exports.cookiePairRex = /(?:[^;"\s]+="[^"]*"|[^;]+)(?=;|$)/g;
8
+ const cookieRex = exports.cookieRex = /^[^=]+=(?:"[^"]*"|[^\p{Control};]*)(?:;\s*(?:[^=]+=(?:"[^"]*"|[^\p{Control};]*)|[^=]+))*$/u;
9
+ const cookiePairRex = exports.cookiePairRex = /[^;\s]+=(?:"[^"]*"|[^;\s]*)/g;
10
10
  const illegalCookieChars = exports.illegalCookieChars = /\p{Control}/u;
11
11
  const isValidCookie = str => str?.constructor === String && cookieRex.test(str);
12
12
  exports.isValidCookie = isValidCookie;
13
13
  const maxCookieLifetimeCap = exports.maxCookieLifetimeCap = 3456e7; // 400 days
14
14
  const maxCookieSize = exports.maxCookieSize = 4096;
15
- const splitCookie = str => str.match(cookiePairRex).map(str => str.trim());
15
+ const splitCookie = str => str.match(cookiePairRex);
16
16
  exports.splitCookie = splitCookie;
17
17
  class Cookies extends URLSearchParams {
18
18
  static #finalizers = new Set();
@@ -42,25 +42,28 @@ class Cookies extends URLSearchParams {
42
42
  if (input.every(it => isValidCookie(it))) {
43
43
  input = input.filter(it => !illegalCookieChars.test(it) && it.length <= maxCookieSize);
44
44
  input = input.map(splitCookie).map(([cookie, ...attrs]) => {
45
- try {
46
- cookie = cookie.split('=').map(it => decodeURIComponent(it.trim()));
47
- return cookie;
48
- } finally {
49
- if (cookiesTTL) {
50
- for (const attr of attrs) {
51
- if (/(?:expires|max-age)=/i.test(attr)) {
52
- const [key, val] = attr.toLowerCase().split('=');
53
- let interval = val * 1e3 || Date.parse(val) - Date.now();
54
- if (interval < 0 || Number.isNaN(interval)) {
55
- interval = 0;
56
- }
57
- ttlMap.set(cookie[0], {
58
- [(0, _utils.toCamelCase)(key.trim())]: Math.min(interval, maxCookieLifetimeCap)
59
- });
45
+ cookie = cookie.split(/=(?<v>.*)/s, 2).map(it => {
46
+ try {
47
+ return decodeURIComponent(it);
48
+ } catch {
49
+ return it;
50
+ }
51
+ });
52
+ if (cookiesTTL) {
53
+ for (const attr of attrs) {
54
+ if (/(?:expires|max-age)=/i.test(attr)) {
55
+ const [key, val] = attr.split(/=(?<v>.*)/s, 2);
56
+ let interval = val * 1e3 || Date.parse(val) - Date.now();
57
+ if (interval < 0 || Number.isNaN(interval)) {
58
+ interval = 0;
60
59
  }
60
+ ttlMap.set(cookie[0], {
61
+ [(0, _utils.toCamelCase)(key)]: Math.min(interval, maxCookieLifetimeCap)
62
+ });
61
63
  }
62
64
  }
63
65
  }
66
+ return cookie;
64
67
  });
65
68
  }
66
69
  }
@@ -96,7 +99,7 @@ class Cookies extends URLSearchParams {
96
99
  }
97
100
  toString() {
98
101
  (0, _utils.brandCheck)(this, Cookies);
99
- return super.toString().split('&').join('; ').trim();
102
+ return super.toString().split('&').join('; ');
100
103
  }
101
104
  }
102
105
  exports.Cookies = Cookies;
package/dist/formdata.cjs CHANGED
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.parseFormData = exports.isFormData = exports.fdToAsyncIterable = exports.FormData = void 0;
7
- var _nodeBuffer = require("node:buffer");
8
7
  var _nodeCrypto = require("node:crypto");
9
8
  var _nodeHttp = _interopRequireDefault(require("node:http2"));
10
9
  var _mediatypes = require("./mediatypes.cjs");
@@ -31,7 +30,7 @@ class FormData {
31
30
  filename &&= String(filename).toWellFormed();
32
31
  if ((0, _utils.isBlobLike)(value)) {
33
32
  filename ??= String(value.name ?? 'blob').toWellFormed();
34
- value = new _nodeBuffer.File([value], filename, value);
33
+ value = new File([value], filename, value);
35
34
  } else if ((0, _utils.isPipeStream)(value) || (0, _utils.isReadableStream)(value)) {
36
35
  value.name = filename ?? 'blob';
37
36
  } else {
package/dist/index.cjs CHANGED
@@ -5,22 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  var _exportNames = {
7
7
  constants: true,
8
- mediatypes: true,
9
- Blob: true,
10
- File: true
8
+ mediatypes: true
11
9
  };
12
- Object.defineProperty(exports, "Blob", {
13
- enumerable: true,
14
- get: function () {
15
- return _nodeBuffer.Blob;
16
- }
17
- });
18
- Object.defineProperty(exports, "File", {
19
- enumerable: true,
20
- get: function () {
21
- return _nodeBuffer.File;
22
- }
23
- });
24
10
  Object.defineProperty(exports, "constants", {
25
11
  enumerable: true,
26
12
  get: function () {
@@ -74,7 +60,6 @@ Object.keys(_validation).forEach(function (key) {
74
60
  }
75
61
  });
76
62
  });
77
- var _nodeBuffer = require("node:buffer");
78
63
  var _ackn = require("./ackn.cjs");
79
64
  Object.keys(_ackn).forEach(function (key) {
80
65
  if (key === "default" || key === "__esModule") return;
package/dist/mixin.cjs CHANGED
@@ -40,7 +40,7 @@ const mixin = (res, {
40
40
  value: async function () {
41
41
  (0, _utils.brandCheck)(this, res?.constructor);
42
42
  const val = await this.arrayBuffer();
43
- return new _nodeBuffer.Blob([val]);
43
+ return new Blob([val]);
44
44
  }
45
45
  },
46
46
  bytes: {
package/dist/transfer.cjs CHANGED
@@ -70,12 +70,15 @@ const transfer = async options => {
70
70
  return res;
71
71
  } catch (err) {
72
72
  if ((0, _utils.isLikelyH2cPrefaceError)(err)) {
73
+ const {
74
+ retry
75
+ } = options;
73
76
  options = (0, _utils.deepMerge)(options, {
74
77
  h2: true,
75
78
  retry: {
76
- attempts: 1,
77
- errorCodes: [err.code],
78
- interval: 0
79
+ attempts: ++retry.attempts,
80
+ errorCodes: [err.code, ...retry.errorCodes],
81
+ interval: 1
79
82
  }
80
83
  });
81
84
  }
package/dist/utils.cjs CHANGED
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.stripHeaders = exports.snoop = exports.sameOrigin = exports.normalizeHeaders = exports.normalize = exports.isReadableStream = exports.isPipeStream = exports.isLikelyH2cPrefaceError = exports.isBlobLike = exports.dispatch = exports.deepMerge = exports.cloneWith = exports.brandCheck = exports.augment = exports.addSearchParams = void 0;
7
7
  exports.tap = tap;
8
8
  exports.unwind = exports.toCamelCase = void 0;
9
- var _nodeBuffer = require("node:buffer");
10
9
  var _nodeHttp = _interopRequireDefault(require("node:http2"));
11
10
  var _nodeStream = require("node:stream");
12
11
  var _config = _interopRequireWildcard(require("./config.cjs"));
@@ -97,7 +96,7 @@ const dispatch = (req, {
97
96
  }
98
97
  };
99
98
  exports.dispatch = dispatch;
100
- const isBlobLike = val => val instanceof _nodeBuffer.Blob;
99
+ const isBlobLike = val => val instanceof Blob;
101
100
  exports.isBlobLike = isBlobLike;
102
101
  const isLikelyH2cPrefaceError = err => err.code === 'HPE_INVALID_CONSTANT';
103
102
  exports.isLikelyH2cPrefaceError = isLikelyH2cPrefaceError;
package/package.json CHANGED
@@ -11,11 +11,11 @@
11
11
  "devDependencies": {
12
12
  "@babel/cli": "^7.28.6",
13
13
  "@babel/core": "^7.29.0",
14
- "@babel/preset-env": "^7.29.0",
15
- "@eslint/markdown": "^7.5.1",
16
- "c8": "^10.1.3",
17
- "eslint": "^10.0.1",
18
- "eslint-config-ultra-refined": "^4.1.2",
14
+ "@babel/preset-env": "^7.29.2",
15
+ "@eslint/markdown": "^8.0.1",
16
+ "c8": "^11.0.0",
17
+ "eslint": "^10.2.0",
18
+ "eslint-config-ultra-refined": "^4.1.6",
19
19
  "mocha": "^11.7.5"
20
20
  },
21
21
  "engines": {
@@ -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.2.5"
75
+ "version": "7.2.7"
76
76
  }
package/src/ackn.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { connect } from 'node:tls';
2
2
 
3
- export const ackn = (options) => new Promise((resolve, reject) => {
4
- const { url } = options;
3
+ export const ackn = (options = {}) => new Promise((resolve, reject) => {
4
+ const url = new URL(options.url);
5
5
  const socket = connect({
6
6
  ...options,
7
7
  ALPNProtocols: [
package/src/config.js CHANGED
@@ -15,6 +15,7 @@ export const isZstdSupported = !!zlib.constants.ZSTD_CLEVEL_DEFAULT;
15
15
  const {
16
16
  HTTP2_HEADER_ACCEPT,
17
17
  HTTP2_HEADER_ACCEPT_ENCODING,
18
+ HTTP2_HEADER_USER_AGENT,
18
19
  HTTP2_METHOD_GET,
19
20
  HTTP_STATUS_BAD_GATEWAY,
20
21
  HTTP_STATUS_GATEWAY_TIMEOUT,
@@ -49,6 +50,7 @@ const defaults = {
49
50
  headers: {
50
51
  [HTTP2_HEADER_ACCEPT]: `${ APPLICATION_JSON }, ${ TEXT_PLAIN }, ${ WILDCARD }`,
51
52
  [HTTP2_HEADER_ACCEPT_ENCODING]: `br,${ isZstdSupported ? ' zstd, ' : ' ' }gzip, deflate, deflate-raw`,
53
+ [HTTP2_HEADER_USER_AGENT]: `node/${ process.versions.node } ${ process.platform }/${ process.arch }`,
52
54
  },
53
55
  method: HTTP2_METHOD_GET,
54
56
  parse: true,
package/src/cookies.js CHANGED
@@ -3,13 +3,13 @@ import {
3
3
  toCamelCase,
4
4
  } from './utils.js';
5
5
 
6
- export const cookieRex = /^[\w-]+=(?:"[^"]*"|[^\p{Control};]*)(?:;\s*(?:[\w-]+=(?:"[^"]*"|[^\p{Control};]*)|[\w-]+))*$/u;
7
- export const cookiePairRex = /(?:[^;"\s]+="[^"]*"|[^;]+)(?=;|$)/g;
6
+ export const cookieRex = /^[^=]+=(?:"[^"]*"|[^\p{Control};]*)(?:;\s*(?:[^=]+=(?:"[^"]*"|[^\p{Control};]*)|[^=]+))*$/u;
7
+ export const cookiePairRex = /[^;\s]+=(?:"[^"]*"|[^;\s]*)/g;
8
8
  export const illegalCookieChars = /\p{Control}/u;
9
9
  export const isValidCookie = (str) => str?.constructor === String && cookieRex.test(str);
10
10
  export const maxCookieLifetimeCap = 3456e7; // 400 days
11
11
  export const maxCookieSize = 4096;
12
- export const splitCookie = (str) => str.match(cookiePairRex).map((str) => str.trim());
12
+ export const splitCookie = (str) => str.match(cookiePairRex);
13
13
 
14
14
  export class Cookies extends URLSearchParams {
15
15
 
@@ -43,29 +43,33 @@ export class Cookies extends URLSearchParams {
43
43
  if (input.every((it) => isValidCookie(it))) {
44
44
  input = input.filter((it) => !illegalCookieChars.test(it) && it.length <= maxCookieSize);
45
45
  input = input.map(splitCookie).map(([cookie, ...attrs]) => {
46
- try {
47
- cookie = cookie.split('=').map((it) => decodeURIComponent(it.trim()));
48
-
49
- return cookie;
50
- } finally {
51
- if (cookiesTTL) {
52
- for (const attr of attrs) {
53
- if (/(?:expires|max-age)=/i.test(attr)) {
54
- const [key, val] = attr.toLowerCase().split('=');
55
- let interval = val * 1e3 || Date.parse(val) - Date.now();
56
-
57
- if (interval < 0 || Number.isNaN(interval)) {
58
- interval = 0;
59
- }
60
-
61
- ttlMap.set(
62
- cookie[0],
63
- { [toCamelCase(key.trim())]: Math.min(interval, maxCookieLifetimeCap) },
64
- );
46
+ cookie = cookie.split(/=(?<v>.*)/s, 2).map((it) => {
47
+ try {
48
+ return decodeURIComponent(it);
49
+ } catch {
50
+ return it;
51
+ }
52
+ });
53
+
54
+ if (cookiesTTL) {
55
+ for (const attr of attrs) {
56
+ if (/(?:expires|max-age)=/i.test(attr)) {
57
+ const [key, val] = attr.split(/=(?<v>.*)/s, 2);
58
+ let interval = val * 1e3 || Date.parse(val) - Date.now();
59
+
60
+ if (interval < 0 || Number.isNaN(interval)) {
61
+ interval = 0;
65
62
  }
63
+
64
+ ttlMap.set(
65
+ cookie[0],
66
+ { [toCamelCase(key)]: Math.min(interval, maxCookieLifetimeCap) },
67
+ );
66
68
  }
67
69
  }
68
70
  }
71
+
72
+ return cookie;
69
73
  });
70
74
  }
71
75
  }
@@ -111,7 +115,7 @@ export class Cookies extends URLSearchParams {
111
115
  toString() {
112
116
  brandCheck(this, Cookies);
113
117
 
114
- return super.toString().split('&').join('; ').trim();
118
+ return super.toString().split('&').join('; ');
115
119
  }
116
120
 
117
121
  }
package/src/formdata.js CHANGED
@@ -1,4 +1,3 @@
1
- import { File } from 'node:buffer';
2
1
  import { randomBytes } from 'node:crypto';
3
2
  import http2 from 'node:http2';
4
3
  import {
package/src/index.js CHANGED
@@ -14,10 +14,6 @@ import {
14
14
  } from './utils.js';
15
15
  import { validation } from './validation.js';
16
16
 
17
- export {
18
- Blob,
19
- File,
20
- } from 'node:buffer';
21
17
  export { constants } from 'node:http2';
22
18
  export * from './ackn.js';
23
19
  export * from './codecs.js';
package/src/mixin.js CHANGED
@@ -1,7 +1,4 @@
1
- import {
2
- Blob,
3
- isUtf8,
4
- } from 'node:buffer';
1
+ import { isUtf8 } from 'node:buffer';
5
2
  import http2 from 'node:http2';
6
3
  import { buffer } from 'node:stream/consumers';
7
4
  import { MIMEType } from 'node:util';
package/src/transfer.js CHANGED
@@ -72,12 +72,17 @@ export const transfer = async (options) => {
72
72
  return res;
73
73
  } catch (err) {
74
74
  if (isLikelyH2cPrefaceError(err)) {
75
+ const { retry } = options;
76
+
75
77
  options = deepMerge(options, {
76
78
  h2: true,
77
79
  retry: {
78
- attempts: 1,
79
- errorCodes: [err.code],
80
- interval: 0,
80
+ attempts: ++retry.attempts,
81
+ errorCodes: [
82
+ err.code,
83
+ ...retry.errorCodes,
84
+ ],
85
+ interval: 1,
81
86
  },
82
87
  });
83
88
  }
package/src/utils.js CHANGED
@@ -1,4 +1,3 @@
1
- import { Blob } from 'node:buffer';
2
1
  import http2 from 'node:http2';
3
2
  import {
4
3
  isReadable,