rekwest 7.2.1 → 7.2.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 +3 -3
- package/dist/cookies.cjs +4 -4
- package/dist/formdata.cjs +8 -9
- package/dist/transfer.cjs +10 -0
- package/dist/utils.cjs +5 -1
- package/package.json +1 -1
- package/src/cookies.js +4 -4
- package/src/formdata.js +8 -9
- 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
|
|
@@ -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/cookies.cjs
CHANGED
|
@@ -30,7 +30,7 @@ class Cookies extends URLSearchParams {
|
|
|
30
30
|
if (Array.isArray(input) && input.every(it => !Array.isArray(it))) {
|
|
31
31
|
input = input.map(it => {
|
|
32
32
|
if (!cookiesTTL) {
|
|
33
|
-
return [it.split(';')
|
|
33
|
+
return [it.split(';')[0].trim()];
|
|
34
34
|
}
|
|
35
35
|
const [cookie, ...attrs] = it.split(';').map(it => it.trim());
|
|
36
36
|
const ttl = {};
|
|
@@ -44,10 +44,10 @@ class Cookies extends URLSearchParams {
|
|
|
44
44
|
return [cookie.replace(/\u0022/g, ''), Object.keys(ttl).length ? ttl : null];
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
|
-
super(Array.isArray(input) ? input.map(it => it
|
|
47
|
+
super(Array.isArray(input) ? input.map(it => it[0]).join('&') : input);
|
|
48
48
|
if (Array.isArray(input) && cookiesTTL) {
|
|
49
|
-
for (const [cookie, ttl] of input.filter(it => it
|
|
50
|
-
const key = cookie.split('=')
|
|
49
|
+
for (const [cookie, ttl] of input.filter(it => it[1])) {
|
|
50
|
+
const key = cookie.split('=')[0];
|
|
51
51
|
if (this.#chronometry.has(key)) {
|
|
52
52
|
clearTimeout(this.#chronometry.get(key));
|
|
53
53
|
this.#chronometry.delete(key);
|
package/dist/formdata.cjs
CHANGED
|
@@ -7,7 +7,6 @@ exports.FormData = void 0;
|
|
|
7
7
|
var _nodeBuffer = require("node:buffer");
|
|
8
8
|
var _nodeCrypto = require("node:crypto");
|
|
9
9
|
var _nodeHttp = _interopRequireDefault(require("node:http2"));
|
|
10
|
-
var _nodeUtil = require("node:util");
|
|
11
10
|
var _mediatypes = require("./mediatypes.cjs");
|
|
12
11
|
var _utils = require("./utils.cjs");
|
|
13
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -44,15 +43,15 @@ class FormData {
|
|
|
44
43
|
return FormData.name === val?.[Symbol.toStringTag];
|
|
45
44
|
}
|
|
46
45
|
static #enfoldEntry(name, value, filename) {
|
|
47
|
-
name = (
|
|
48
|
-
filename &&= (
|
|
46
|
+
name = String(name).toWellFormed();
|
|
47
|
+
filename &&= String(filename).toWellFormed();
|
|
49
48
|
if ((0, _utils.isFileLike)(value)) {
|
|
50
49
|
filename ??= value.name || 'blob';
|
|
51
50
|
value = new _nodeBuffer.File([value], filename, value);
|
|
52
51
|
} else if (this.#ensureInstance(value)) {
|
|
53
52
|
value.name = filename;
|
|
54
53
|
} else {
|
|
55
|
-
value = (
|
|
54
|
+
value = String(value).toWellFormed();
|
|
56
55
|
}
|
|
57
56
|
return {
|
|
58
57
|
name,
|
|
@@ -106,7 +105,7 @@ class FormData {
|
|
|
106
105
|
delete(...args) {
|
|
107
106
|
(0, _utils.brandCheck)(this, FormData);
|
|
108
107
|
this.#ensureArgs(args, 1, 'delete');
|
|
109
|
-
const name = (
|
|
108
|
+
const name = String(args[0]).toWellFormed();
|
|
110
109
|
this.#entries = this.#entries.filter(it => it.name !== name);
|
|
111
110
|
}
|
|
112
111
|
forEach(...args) {
|
|
@@ -120,19 +119,19 @@ class FormData {
|
|
|
120
119
|
get(...args) {
|
|
121
120
|
(0, _utils.brandCheck)(this, FormData);
|
|
122
121
|
this.#ensureArgs(args, 1, 'get');
|
|
123
|
-
const name = (
|
|
124
|
-
return
|
|
122
|
+
const name = String(args[0]).toWellFormed();
|
|
123
|
+
return this.#entries.find(it => it.name === name)?.value ?? null;
|
|
125
124
|
}
|
|
126
125
|
getAll(...args) {
|
|
127
126
|
(0, _utils.brandCheck)(this, FormData);
|
|
128
127
|
this.#ensureArgs(args, 1, 'getAll');
|
|
129
|
-
const name = (
|
|
128
|
+
const name = String(args[0]).toWellFormed();
|
|
130
129
|
return this.#entries.filter(it => it.name === name).map(it => it.value);
|
|
131
130
|
}
|
|
132
131
|
has(...args) {
|
|
133
132
|
(0, _utils.brandCheck)(this, FormData);
|
|
134
133
|
this.#ensureArgs(args, 1, 'has');
|
|
135
|
-
const name = (
|
|
134
|
+
const name = String(args[0]).toWellFormed();
|
|
136
135
|
return !!this.#entries.find(it => it.name === name);
|
|
137
136
|
}
|
|
138
137
|
set(...args) {
|
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/cookies.js
CHANGED
|
@@ -30,7 +30,7 @@ export class Cookies extends URLSearchParams {
|
|
|
30
30
|
if (Array.isArray(input) && input.every((it) => !Array.isArray(it))) {
|
|
31
31
|
input = input.map((it) => {
|
|
32
32
|
if (!cookiesTTL) {
|
|
33
|
-
return [it.split(';')
|
|
33
|
+
return [it.split(';')[0].trim()];
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
const [cookie, ...attrs] = it.split(';').map((it) => it.trim());
|
|
@@ -52,11 +52,11 @@ export class Cookies extends URLSearchParams {
|
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
super(Array.isArray(input) ? input.map((it) => it
|
|
55
|
+
super(Array.isArray(input) ? input.map((it) => it[0]).join('&') : input);
|
|
56
56
|
|
|
57
57
|
if (Array.isArray(input) && cookiesTTL) {
|
|
58
|
-
for (const [cookie, ttl] of input.filter((it) => it
|
|
59
|
-
const key = cookie.split('=')
|
|
58
|
+
for (const [cookie, ttl] of input.filter((it) => it[1])) {
|
|
59
|
+
const key = cookie.split('=')[0];
|
|
60
60
|
|
|
61
61
|
if (this.#chronometry.has(key)) {
|
|
62
62
|
clearTimeout(this.#chronometry.get(key));
|
package/src/formdata.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { File } from 'node:buffer';
|
|
2
2
|
import { randomBytes } from 'node:crypto';
|
|
3
3
|
import http2 from 'node:http2';
|
|
4
|
-
import { toUSVString } from 'node:util';
|
|
5
4
|
import {
|
|
6
5
|
APPLICATION_OCTET_STREAM,
|
|
7
6
|
MULTIPART_FORM_DATA,
|
|
@@ -64,8 +63,8 @@ export class FormData {
|
|
|
64
63
|
}
|
|
65
64
|
|
|
66
65
|
static #enfoldEntry(name, value, filename) {
|
|
67
|
-
name =
|
|
68
|
-
filename &&=
|
|
66
|
+
name = String(name).toWellFormed();
|
|
67
|
+
filename &&= String(filename).toWellFormed();
|
|
69
68
|
|
|
70
69
|
if (isFileLike(value)) {
|
|
71
70
|
filename ??= value.name || 'blob';
|
|
@@ -73,7 +72,7 @@ export class FormData {
|
|
|
73
72
|
} else if (this.#ensureInstance(value)) {
|
|
74
73
|
value.name = filename;
|
|
75
74
|
} else {
|
|
76
|
-
value =
|
|
75
|
+
value = String(value).toWellFormed();
|
|
77
76
|
}
|
|
78
77
|
|
|
79
78
|
return {
|
|
@@ -152,7 +151,7 @@ export class FormData {
|
|
|
152
151
|
delete(...args) {
|
|
153
152
|
brandCheck(this, FormData);
|
|
154
153
|
this.#ensureArgs(args, 1, 'delete');
|
|
155
|
-
const name =
|
|
154
|
+
const name = String(args[0]).toWellFormed();
|
|
156
155
|
|
|
157
156
|
this.#entries = this.#entries.filter((it) => it.name !== name);
|
|
158
157
|
}
|
|
@@ -173,15 +172,15 @@ export class FormData {
|
|
|
173
172
|
get(...args) {
|
|
174
173
|
brandCheck(this, FormData);
|
|
175
174
|
this.#ensureArgs(args, 1, 'get');
|
|
176
|
-
const name =
|
|
175
|
+
const name = String(args[0]).toWellFormed();
|
|
177
176
|
|
|
178
|
-
return
|
|
177
|
+
return this.#entries.find((it) => it.name === name)?.value ?? null;
|
|
179
178
|
}
|
|
180
179
|
|
|
181
180
|
getAll(...args) {
|
|
182
181
|
brandCheck(this, FormData);
|
|
183
182
|
this.#ensureArgs(args, 1, 'getAll');
|
|
184
|
-
const name =
|
|
183
|
+
const name = String(args[0]).toWellFormed();
|
|
185
184
|
|
|
186
185
|
return this.#entries.filter((it) => it.name === name).map((it) => it.value);
|
|
187
186
|
}
|
|
@@ -189,7 +188,7 @@ export class FormData {
|
|
|
189
188
|
has(...args) {
|
|
190
189
|
brandCheck(this, FormData);
|
|
191
190
|
this.#ensureArgs(args, 1, 'has');
|
|
192
|
-
const name =
|
|
191
|
+
const name = String(args[0]).toWellFormed();
|
|
193
192
|
|
|
194
193
|
return !!this.#entries.find((it) => it.name === name);
|
|
195
194
|
}
|
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
|
};
|