rekwest 7.2.1 → 7.2.2

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
@@ -7,7 +7,7 @@ and [http2.request](https://nodejs.org/api/http2.html#clienthttp2sessionrequesth
7
7
  ## Abstract
8
8
 
9
9
  * Fetch-alike 🥏
10
- * Cool-beans 🫐 config options (with defaults)
10
+ * Cool-beans 🫐 config options (with defaults) 📋
11
11
  * Automatic HTTP/2 support (ALPN negotiation) 💼
12
12
  * Automatic or opt-in body parse (with non-UTF-8 charset decoding) 🉑
13
13
  * Automatic and simplistic `Cookies` treatment (with **TTL** support) 🍪
@@ -17,7 +17,7 @@ and [http2.request](https://nodejs.org/api/http2.html#clienthttp2sessionrequesth
17
17
  * Support redirects & retries with fine-grained tune-ups 🪛
18
18
  * Support plenty request body types (include blobs & streams) 📦
19
19
  * Support both CJS and ESM module systems 🧩
20
- * Fully promise-able and pipe-able 🔗
20
+ * Fully promise-able and pipe-able 🌀
21
21
  * Zero dependencies 🗽
22
22
 
23
23
  ## Prerequisites
@@ -207,7 +207,7 @@ const params = {
207
207
  signature: '[code]',
208
208
  variant: 'A',
209
209
  };
210
- const signal = AbortSignal.timeout(1e4);
210
+ const signal = AbortSignal.timeout(3e4);
211
211
  const url = '/somewhat/endpoint';
212
212
 
213
213
  const res = await rk(url, {
package/dist/transfer.cjs CHANGED
@@ -71,6 +71,16 @@ const transfer = async options => {
71
71
  }
72
72
  return res;
73
73
  } catch (err) {
74
+ if ((0, _utils.isLikelyH2cPrefaceError)(err)) {
75
+ options = (0, _utils.deepMerge)(options, {
76
+ h2: true,
77
+ retry: {
78
+ attempts: 1,
79
+ errorCodes: [err.code],
80
+ interval: 0
81
+ }
82
+ });
83
+ }
74
84
  const result = (0, _retries.retries)(err, options);
75
85
  if (result) {
76
86
  return result;
package/dist/utils.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.stripHeaders = exports.snoop = exports.sameOrigin = exports.normalizeHeaders = exports.normalize = exports.isReadableStream = exports.isPipeStream = exports.isFileLike = exports.dispatch = exports.deepMerge = exports.cloneWith = exports.brandCheck = exports.augment = exports.addSearchParams = void 0;
6
+ exports.stripHeaders = exports.snoop = exports.sameOrigin = exports.normalizeHeaders = exports.normalize = exports.isReadableStream = exports.isPipeStream = exports.isLikelyH2cPrefaceError = exports.isFileLike = 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
9
  var _nodeBuffer = require("node:buffer");
@@ -102,6 +102,10 @@ const isFileLike = val => {
102
102
  return [_nodeBuffer.Blob, _nodeBuffer.File].some(it => val instanceof it);
103
103
  };
104
104
  exports.isFileLike = isFileLike;
105
+ const isLikelyH2cPrefaceError = err => {
106
+ return err.code === 'HPE_INVALID_CONSTANT';
107
+ };
108
+ exports.isLikelyH2cPrefaceError = isLikelyH2cPrefaceError;
105
109
  const isPipeStream = val => {
106
110
  return val instanceof _nodeStream.Readable;
107
111
  };
package/package.json CHANGED
@@ -71,5 +71,5 @@
71
71
  "test:cover": "c8 --include=src --reporter=lcov --reporter=text npm test"
72
72
  },
73
73
  "type": "module",
74
- "version": "7.2.1"
74
+ "version": "7.2.2"
75
75
  }
package/src/transfer.js CHANGED
@@ -8,7 +8,9 @@ import { preflight } from './preflight.js';
8
8
  import { retries } from './retries.js';
9
9
  import { transform } from './transform.js';
10
10
  import {
11
+ deepMerge,
11
12
  dispatch,
13
+ isLikelyH2cPrefaceError,
12
14
  snoop,
13
15
  } from './utils.js';
14
16
 
@@ -73,6 +75,17 @@ export const transfer = async (options) => {
73
75
 
74
76
  return res;
75
77
  } catch (err) {
78
+ if (isLikelyH2cPrefaceError(err)) {
79
+ options = deepMerge(options, {
80
+ h2: true,
81
+ retry: {
82
+ attempts: 1,
83
+ errorCodes: [err.code],
84
+ interval: 0,
85
+ },
86
+ });
87
+ }
88
+
76
89
  const result = retries(err, options);
77
90
 
78
91
  if (result) {
package/src/utils.js CHANGED
@@ -109,6 +109,10 @@ export const isFileLike = (val) => {
109
109
  ].some((it) => val instanceof it);
110
110
  };
111
111
 
112
+ export const isLikelyH2cPrefaceError = (err) => {
113
+ return err.code === 'HPE_INVALID_CONSTANT';
114
+ };
115
+
112
116
  export const isPipeStream = (val) => {
113
117
  return val instanceof Readable;
114
118
  };