rekwest 2.3.1 → 2.3.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/dist/formdata.js +6 -5
- package/dist/helpers.js +2 -2
- package/package.json +12 -8
- package/src/formdata.mjs +7 -6
- package/src/helpers.mjs +2 -2
package/dist/formdata.js
CHANGED
|
@@ -17,6 +17,7 @@ var _mediatypes = require("./mediatypes.mjs");
|
|
|
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
|
@@ -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,
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
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.
|
|
11
|
+
"@babel/cli": "^7.16.8",
|
|
12
|
+
"@babel/core": "^7.16.7",
|
|
13
|
+
"@babel/eslint-parser": "^7.16.5",
|
|
14
|
+
"@babel/preset-env": "^7.16.8",
|
|
15
|
+
"c8": "^7.11.0",
|
|
16
|
+
"eslint": "^8.6.0",
|
|
17
|
+
"eslint-config-ultra-refined": "^2.3.0",
|
|
18
18
|
"mocha": "^9.1.3"
|
|
19
19
|
},
|
|
20
20
|
"description": "The robust request library that humanity deserves 🌐",
|
|
@@ -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",
|
|
@@ -55,5 +59,5 @@
|
|
|
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.2"
|
|
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,
|