rekwest 2.3.1 → 2.3.5
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/formdata.js +9 -8
- package/dist/helpers.js +17 -22
- package/dist/index.js +7 -7
- package/package.json +14 -10
- package/src/formdata.mjs +7 -6
- package/src/helpers.mjs +17 -23
package/dist/formdata.js
CHANGED
|
@@ -9,14 +9,15 @@ var _http = _interopRequireDefault(require("http2"));
|
|
|
9
9
|
|
|
10
10
|
var _util = require("util");
|
|
11
11
|
|
|
12
|
-
var _file = require("./file.
|
|
12
|
+
var _file = require("./file.js");
|
|
13
13
|
|
|
14
|
-
var _helpers = require("./helpers.
|
|
14
|
+
var _helpers = require("./helpers.js");
|
|
15
15
|
|
|
16
|
-
var _mediatypes = require("./mediatypes.
|
|
16
|
+
var _mediatypes = require("./mediatypes.js");
|
|
17
17
|
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
19
|
|
|
20
|
+
const CRLF = '\r\n';
|
|
20
21
|
const {
|
|
21
22
|
HTTP2_HEADER_CONTENT_DISPOSITION,
|
|
22
23
|
HTTP2_HEADER_CONTENT_TYPE
|
|
@@ -26,11 +27,11 @@ class FormData {
|
|
|
26
27
|
static actuate(fd) {
|
|
27
28
|
const boundary = (0, _crypto.randomBytes)(24).toString('hex');
|
|
28
29
|
const contentType = `${_mediatypes.MULTIPART_FORM_DATA}; boundary=${boundary}`;
|
|
29
|
-
const prefix = `--${boundary}
|
|
30
|
+
const prefix = `--${boundary}${CRLF}${HTTP2_HEADER_CONTENT_DISPOSITION}: form-data`;
|
|
30
31
|
|
|
31
32
|
const escape = str => str.replace(/\n/g, '%0A').replace(/\r/g, '%0D').replace(/"/g, '%22');
|
|
32
33
|
|
|
33
|
-
const normalize = value => value.replace(/\r?\n|\r/g,
|
|
34
|
+
const normalize = value => value.replace(/\r?\n|\r/g, CRLF);
|
|
34
35
|
|
|
35
36
|
return {
|
|
36
37
|
contentType,
|
|
@@ -40,11 +41,11 @@ class FormData {
|
|
|
40
41
|
|
|
41
42
|
for (const [name, value] of fd) {
|
|
42
43
|
if (value.constructor === String) {
|
|
43
|
-
yield encoder.encode(`${prefix}; name="${escape(normalize(name))}"
|
|
44
|
+
yield encoder.encode(`${prefix}; name="${escape(normalize(name))}"${CRLF.repeat(2)}${normalize(value)}${CRLF}`);
|
|
44
45
|
} else {
|
|
45
|
-
yield encoder.encode(`${prefix}; name="${escape(normalize(name))}"${value.name ? `; filename="${escape(value.name)}"` : ''}
|
|
46
|
+
yield encoder.encode(`${prefix}; name="${escape(normalize(name))}"${value.name ? `; filename="${escape(value.name)}"` : ''}${CRLF}${HTTP2_HEADER_CONTENT_TYPE}: ${value.type || _mediatypes.APPLICATION_OCTET_STREAM}${CRLF.repeat(2)}`);
|
|
46
47
|
yield* (0, _helpers.tap)(value);
|
|
47
|
-
yield encoder.encode(
|
|
48
|
+
yield encoder.encode(CRLF);
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
|
package/dist/helpers.js
CHANGED
|
@@ -17,13 +17,13 @@ var _util = require("util");
|
|
|
17
17
|
|
|
18
18
|
var _zlib = _interopRequireDefault(require("zlib"));
|
|
19
19
|
|
|
20
|
-
var _cookies = require("./cookies.
|
|
20
|
+
var _cookies = require("./cookies.js");
|
|
21
21
|
|
|
22
|
-
var _file = require("./file.
|
|
22
|
+
var _file = require("./file.js");
|
|
23
23
|
|
|
24
|
-
var _formdata = require("./formdata.
|
|
24
|
+
var _formdata = require("./formdata.js");
|
|
25
25
|
|
|
26
|
-
var _mediatypes = require("./mediatypes.
|
|
26
|
+
var _mediatypes = require("./mediatypes.js");
|
|
27
27
|
|
|
28
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
29
|
|
|
@@ -51,7 +51,7 @@ const inflate = (0, _util.promisify)(_zlib.default.inflate);
|
|
|
51
51
|
const compress = (buf, encoding, {
|
|
52
52
|
async = false
|
|
53
53
|
} = {}) => {
|
|
54
|
-
encoding &&= encoding.match(
|
|
54
|
+
encoding &&= encoding.match(/(?<encoding>\bbr\b|\bdeflate\b|\bgzip\b)/i)?.groups.encoding.toLowerCase();
|
|
55
55
|
const compressor = {
|
|
56
56
|
br: async ? brotliCompress : _zlib.default.brotliCompressSync,
|
|
57
57
|
deflate: async ? deflate : _zlib.default.deflateSync,
|
|
@@ -65,7 +65,7 @@ exports.compress = compress;
|
|
|
65
65
|
const decompress = (buf, encoding, {
|
|
66
66
|
async = false
|
|
67
67
|
} = {}) => {
|
|
68
|
-
encoding &&= encoding.match(
|
|
68
|
+
encoding &&= encoding.match(/(?<encoding>\bbr\b|\bdeflate\b|\bgzip\b)/i)?.groups.encoding.toLowerCase();
|
|
69
69
|
const decompressor = {
|
|
70
70
|
br: async ? brotliDecompress : _zlib.default.brotliDecompressSync,
|
|
71
71
|
deflate: async ? inflate : _zlib.default.inflateSync,
|
|
@@ -199,36 +199,31 @@ const premix = (res, {
|
|
|
199
199
|
Object.defineProperties(res, {
|
|
200
200
|
arrayBuffer: {
|
|
201
201
|
enumerable: true,
|
|
202
|
-
value:
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const {
|
|
202
|
+
value: function () {
|
|
203
|
+
parse &&= false;
|
|
204
|
+
return this.body().then(({
|
|
206
205
|
buffer,
|
|
207
206
|
byteLength,
|
|
208
207
|
byteOffset
|
|
209
|
-
}
|
|
210
|
-
return buffer.slice(byteOffset, byteOffset + byteLength);
|
|
208
|
+
}) => buffer.slice(byteOffset, byteOffset + byteLength));
|
|
211
209
|
}
|
|
212
210
|
},
|
|
213
211
|
blob: {
|
|
214
212
|
enumerable: true,
|
|
215
|
-
value:
|
|
216
|
-
|
|
217
|
-
return new _buffer.Blob([val]);
|
|
213
|
+
value: function () {
|
|
214
|
+
return this.arrayBuffer().then(res => new _buffer.Blob([res]));
|
|
218
215
|
}
|
|
219
216
|
},
|
|
220
217
|
json: {
|
|
221
218
|
enumerable: true,
|
|
222
|
-
value:
|
|
223
|
-
|
|
224
|
-
return JSON.parse(val);
|
|
219
|
+
value: function () {
|
|
220
|
+
return this.text().then(res => JSON.parse(res));
|
|
225
221
|
}
|
|
226
222
|
},
|
|
227
223
|
text: {
|
|
228
224
|
enumerable: true,
|
|
229
|
-
value:
|
|
230
|
-
|
|
231
|
-
return val.toString();
|
|
225
|
+
value: function () {
|
|
226
|
+
return this.blob().then(blob => blob.text());
|
|
232
227
|
}
|
|
233
228
|
}
|
|
234
229
|
});
|
|
@@ -258,7 +253,7 @@ const premix = (res, {
|
|
|
258
253
|
|
|
259
254
|
if (spool.length && parse) {
|
|
260
255
|
const contentType = this.headers[HTTP2_HEADER_CONTENT_TYPE] ?? '';
|
|
261
|
-
const charset = contentType.split(';').find(it => /charset=/i.test(it))?.toLowerCase()
|
|
256
|
+
const charset = contentType.split(';').find(it => /charset=/i.test(it))?.toLowerCase().replace('charset=', '').replace('iso-8859-1', 'latin1').trim() || 'utf-8';
|
|
262
257
|
|
|
263
258
|
if (/\bjson\b/i.test(contentType)) {
|
|
264
259
|
spool = JSON.parse(spool.toString(charset));
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ exports.constants = _http.constants;
|
|
|
13
13
|
|
|
14
14
|
var _https = require("https");
|
|
15
15
|
|
|
16
|
-
var _ackn = require("./ackn.
|
|
16
|
+
var _ackn = require("./ackn.js");
|
|
17
17
|
|
|
18
18
|
Object.keys(_ackn).forEach(function (key) {
|
|
19
19
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -22,7 +22,7 @@ Object.keys(_ackn).forEach(function (key) {
|
|
|
22
22
|
exports[key] = _ackn[key];
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
var _cookies = require("./cookies.
|
|
25
|
+
var _cookies = require("./cookies.js");
|
|
26
26
|
|
|
27
27
|
Object.keys(_cookies).forEach(function (key) {
|
|
28
28
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -31,7 +31,7 @@ Object.keys(_cookies).forEach(function (key) {
|
|
|
31
31
|
exports[key] = _cookies[key];
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
var _errors = require("./errors.
|
|
34
|
+
var _errors = require("./errors.js");
|
|
35
35
|
|
|
36
36
|
Object.keys(_errors).forEach(function (key) {
|
|
37
37
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -40,7 +40,7 @@ Object.keys(_errors).forEach(function (key) {
|
|
|
40
40
|
exports[key] = _errors[key];
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
var _helpers = require("./helpers.
|
|
43
|
+
var _helpers = require("./helpers.js");
|
|
44
44
|
|
|
45
45
|
Object.keys(_helpers).forEach(function (key) {
|
|
46
46
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -49,9 +49,9 @@ Object.keys(_helpers).forEach(function (key) {
|
|
|
49
49
|
exports[key] = _helpers[key];
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
var _mediatypes = require("./mediatypes.
|
|
52
|
+
var _mediatypes = require("./mediatypes.js");
|
|
53
53
|
|
|
54
|
-
var _file = require("./file.
|
|
54
|
+
var _file = require("./file.js");
|
|
55
55
|
|
|
56
56
|
Object.keys(_file).forEach(function (key) {
|
|
57
57
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -60,7 +60,7 @@ Object.keys(_file).forEach(function (key) {
|
|
|
60
60
|
exports[key] = _file[key];
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
-
var _formdata = require("./formdata.
|
|
63
|
+
var _formdata = require("./formdata.js");
|
|
64
64
|
|
|
65
65
|
Object.keys(_formdata).forEach(function (key) {
|
|
66
66
|
if (key === "default" || key === "__esModule") return;
|
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.16.
|
|
12
|
-
"@babel/core": "^7.16.
|
|
13
|
-
"@babel/eslint-parser": "^7.16.
|
|
14
|
-
"@babel/preset-env": "^7.16.
|
|
15
|
-
"c8": "^7.
|
|
16
|
-
"eslint": "^8.
|
|
17
|
-
"eslint-config-ultra-refined": "^2.
|
|
18
|
-
"mocha": "^9.
|
|
11
|
+
"@babel/cli": "^7.16.8",
|
|
12
|
+
"@babel/core": "^7.16.12",
|
|
13
|
+
"@babel/eslint-parser": "^7.16.5",
|
|
14
|
+
"@babel/preset-env": "^7.16.11",
|
|
15
|
+
"c8": "^7.11.0",
|
|
16
|
+
"eslint": "^8.7.0",
|
|
17
|
+
"eslint-config-ultra-refined": "^2.3.0",
|
|
18
|
+
"mocha": "^9.2.0"
|
|
19
19
|
},
|
|
20
20
|
"description": "The robust request library that humanity deserves 🌐",
|
|
21
21
|
"engines": {
|
|
@@ -33,9 +33,13 @@
|
|
|
33
33
|
"keywords": [
|
|
34
34
|
"fetch",
|
|
35
35
|
"fetch-alike",
|
|
36
|
+
"formdata",
|
|
36
37
|
"http",
|
|
37
38
|
"https",
|
|
39
|
+
"h2",
|
|
40
|
+
"h2c",
|
|
38
41
|
"http2",
|
|
42
|
+
"multipart",
|
|
39
43
|
"request"
|
|
40
44
|
],
|
|
41
45
|
"license": "MIT",
|
|
@@ -50,10 +54,10 @@
|
|
|
50
54
|
"cert:gen": "openssl req -days 365 -keyout localhost.key -newkey ec -nodes -pkeyopt ec_paramgen_curve:prime256v1 -subj //SKIP=1/CN=localhost -out localhost.cert -x509",
|
|
51
55
|
"cert:ken": "openssl x509 -in localhost.cert -noout -text",
|
|
52
56
|
"lint": "eslint . --ext .cjs,.js,.mjs",
|
|
53
|
-
"prepack": "npm run build",
|
|
57
|
+
"prepack": "npm run build && sh pony.sh",
|
|
54
58
|
"pretest": "rm -rf coverage && npm run cert:gen",
|
|
55
59
|
"test": "mocha --exit --recursive",
|
|
56
60
|
"test:cover": "c8 --include=src --reporter=lcov --reporter=text npm test"
|
|
57
61
|
},
|
|
58
|
-
"version": "2.3.
|
|
62
|
+
"version": "2.3.5"
|
|
59
63
|
}
|
package/src/formdata.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
MULTIPART_FORM_DATA,
|
|
9
9
|
} from './mediatypes.mjs';
|
|
10
10
|
|
|
11
|
+
const CRLF = '\r\n';
|
|
11
12
|
const {
|
|
12
13
|
HTTP2_HEADER_CONTENT_DISPOSITION,
|
|
13
14
|
HTTP2_HEADER_CONTENT_TYPE,
|
|
@@ -18,10 +19,10 @@ export class FormData {
|
|
|
18
19
|
static actuate(fd) {
|
|
19
20
|
const boundary = randomBytes(24).toString('hex');
|
|
20
21
|
const contentType = `${ MULTIPART_FORM_DATA }; boundary=${ boundary }`;
|
|
21
|
-
const prefix = `--${ boundary }
|
|
22
|
+
const prefix = `--${ boundary }${ CRLF }${ HTTP2_HEADER_CONTENT_DISPOSITION }: form-data`;
|
|
22
23
|
|
|
23
24
|
const escape = (str) => str.replace(/\n/g, '%0A').replace(/\r/g, '%0D').replace(/"/g, '%22');
|
|
24
|
-
const normalize = (value) => value.replace(/\r?\n|\r/g,
|
|
25
|
+
const normalize = (value) => value.replace(/\r?\n|\r/g, CRLF);
|
|
25
26
|
|
|
26
27
|
return {
|
|
27
28
|
contentType,
|
|
@@ -32,17 +33,17 @@ export class FormData {
|
|
|
32
33
|
if (value.constructor === String) {
|
|
33
34
|
yield encoder.encode(`${ prefix }; name="${
|
|
34
35
|
escape(normalize(name))
|
|
35
|
-
}"
|
|
36
|
+
}"${ CRLF.repeat(2) }${ normalize(value) }${ CRLF }`);
|
|
36
37
|
} else {
|
|
37
38
|
yield encoder.encode(`${ prefix }; name="${
|
|
38
39
|
escape(normalize(name))
|
|
39
|
-
}"${ value.name ? `; filename="${ escape(value.name) }"` : '' }
|
|
40
|
+
}"${ value.name ? `; filename="${ escape(value.name) }"` : '' }${ CRLF }${
|
|
40
41
|
HTTP2_HEADER_CONTENT_TYPE
|
|
41
42
|
}: ${
|
|
42
43
|
value.type || APPLICATION_OCTET_STREAM
|
|
43
|
-
}
|
|
44
|
+
}${ CRLF.repeat(2) }`);
|
|
44
45
|
yield* tap(value);
|
|
45
|
-
yield encoder.encode(
|
|
46
|
+
yield encoder.encode(CRLF);
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
|
package/src/helpers.mjs
CHANGED
|
@@ -44,7 +44,7 @@ const deflate = promisify(zlib.deflate);
|
|
|
44
44
|
const inflate = promisify(zlib.inflate);
|
|
45
45
|
|
|
46
46
|
export const compress = (buf, encoding, { async = false } = {}) => {
|
|
47
|
-
encoding &&= encoding.match(
|
|
47
|
+
encoding &&= encoding.match(/(?<encoding>\bbr\b|\bdeflate\b|\bgzip\b)/i)?.groups.encoding.toLowerCase();
|
|
48
48
|
const compressor = {
|
|
49
49
|
br: async ? brotliCompress : zlib.brotliCompressSync,
|
|
50
50
|
deflate: async ? deflate : zlib.deflateSync,
|
|
@@ -55,7 +55,7 @@ export const compress = (buf, encoding, { async = false } = {}) => {
|
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
export const decompress = (buf, encoding, { async = false } = {}) => {
|
|
58
|
-
encoding &&= encoding.match(
|
|
58
|
+
encoding &&= encoding.match(/(?<encoding>\bbr\b|\bdeflate\b|\bgzip\b)/i)?.groups.encoding.toLowerCase();
|
|
59
59
|
const decompressor = {
|
|
60
60
|
br: async ? brotliDecompress : zlib.brotliDecompressSync,
|
|
61
61
|
deflate: async ? inflate : zlib.inflateSync,
|
|
@@ -182,37 +182,31 @@ export const premix = (res, { digest = false, parse = false } = {}) => {
|
|
|
182
182
|
Object.defineProperties(res, {
|
|
183
183
|
arrayBuffer: {
|
|
184
184
|
enumerable: true,
|
|
185
|
-
value:
|
|
186
|
-
|
|
185
|
+
value: function () {
|
|
186
|
+
parse &&= false;
|
|
187
187
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
188
|
+
return this.body().then(({ buffer, byteLength, byteOffset }) => buffer.slice(
|
|
189
|
+
byteOffset,
|
|
190
|
+
byteOffset + byteLength,
|
|
191
|
+
));
|
|
192
192
|
},
|
|
193
193
|
},
|
|
194
194
|
blob: {
|
|
195
195
|
enumerable: true,
|
|
196
|
-
value:
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return new Blob([val]);
|
|
196
|
+
value: function () {
|
|
197
|
+
return this.arrayBuffer().then((res) => new Blob([res]));
|
|
200
198
|
},
|
|
201
199
|
},
|
|
202
200
|
json: {
|
|
203
201
|
enumerable: true,
|
|
204
|
-
value:
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
return JSON.parse(val);
|
|
202
|
+
value: function () {
|
|
203
|
+
return this.text().then((res) => JSON.parse(res));
|
|
208
204
|
},
|
|
209
205
|
},
|
|
210
206
|
text: {
|
|
211
207
|
enumerable: true,
|
|
212
|
-
value:
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
return val.toString();
|
|
208
|
+
value: function () {
|
|
209
|
+
return this.blob().then((blob) => blob.text());
|
|
216
210
|
},
|
|
217
211
|
},
|
|
218
212
|
});
|
|
@@ -243,9 +237,9 @@ export const premix = (res, { digest = false, parse = false } = {}) => {
|
|
|
243
237
|
const charset = contentType.split(';')
|
|
244
238
|
.find((it) => /charset=/i.test(it))
|
|
245
239
|
?.toLowerCase()
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
240
|
+
.replace('charset=', '')
|
|
241
|
+
.replace('iso-8859-1', 'latin1')
|
|
242
|
+
.trim() || 'utf-8';
|
|
249
243
|
|
|
250
244
|
if (/\bjson\b/i.test(contentType)) {
|
|
251
245
|
spool = JSON.parse(spool.toString(charset));
|