rekwest 7.2.0 → 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 +6 -6
- package/dist/transfer.cjs +10 -0
- package/dist/utils.cjs +5 -1
- package/package.json +1 -1
- package/src/transfer.js +13 -0
- package/src/utils.js +4 -0
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
|
|
@@ -48,7 +48,7 @@ const res = await rekwest(url, {
|
|
|
48
48
|
body: { celestial: 'payload' },
|
|
49
49
|
headers: {
|
|
50
50
|
[HTTP2_HEADER_AUTHORIZATION]: 'Bearer [token]',
|
|
51
|
-
[HTTP2_HEADER_CONTENT_ENCODING]: 'br', //
|
|
51
|
+
[HTTP2_HEADER_CONTENT_ENCODING]: 'br', // Enables: body encoding
|
|
52
52
|
/** [HTTP2_HEADER_CONTENT_TYPE] is undue for
|
|
53
53
|
* Array/Blob/File/FormData/Object/URLSearchParams body types
|
|
54
54
|
* and will be set automatically, with an option to override it here
|
|
@@ -85,7 +85,7 @@ const file = new File(['bits'], 'file.xyz');
|
|
|
85
85
|
const readable = Readable.from('bits');
|
|
86
86
|
|
|
87
87
|
const fd = new FormData({
|
|
88
|
-
aux: Date.now(), //
|
|
88
|
+
aux: Date.now(), // Either [[key, value]] or kv sequenceable
|
|
89
89
|
});
|
|
90
90
|
|
|
91
91
|
fd.append('celestial', 'payload');
|
|
@@ -99,7 +99,7 @@ const res = await rekwest(url, {
|
|
|
99
99
|
body: fd,
|
|
100
100
|
headers: {
|
|
101
101
|
[HTTP2_HEADER_AUTHORIZATION]: 'Bearer [token]',
|
|
102
|
-
[HTTP2_HEADER_CONTENT_ENCODING]: 'zstd', //
|
|
102
|
+
[HTTP2_HEADER_CONTENT_ENCODING]: 'zstd', // Enables: body encoding
|
|
103
103
|
},
|
|
104
104
|
method: HTTP2_METHOD_POST,
|
|
105
105
|
});
|
|
@@ -207,7 +207,7 @@ const params = {
|
|
|
207
207
|
signature: '[code]',
|
|
208
208
|
variant: 'A',
|
|
209
209
|
};
|
|
210
|
-
const signal = AbortSignal.timeout(
|
|
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
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
|
};
|