@faasjs/request 2.3.1 → 2.4.0
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/index.js +7 -14
- package/dist/index.mjs +7 -14
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -31,8 +31,7 @@ function querystringify(obj) {
|
|
|
31
31
|
}
|
|
32
32
|
key = encodeURIComponent(key);
|
|
33
33
|
value = encodeURIComponent(value);
|
|
34
|
-
if (key === null || value === null)
|
|
35
|
-
continue;
|
|
34
|
+
if (key === null || value === null) continue;
|
|
36
35
|
pairs.push(`${key}=${value}`);
|
|
37
36
|
}
|
|
38
37
|
}
|
|
@@ -58,18 +57,14 @@ async function request(url$1, options = { headers: {} }) {
|
|
|
58
57
|
return mock(url$1, options);
|
|
59
58
|
}
|
|
60
59
|
if (options.query) {
|
|
61
|
-
if (!url$1.includes("?"))
|
|
62
|
-
|
|
63
|
-
else if (!url$1.endsWith("?"))
|
|
64
|
-
url$1 += "&";
|
|
60
|
+
if (!url$1.includes("?")) url$1 += "?";
|
|
61
|
+
else if (!url$1.endsWith("?")) url$1 += "&";
|
|
65
62
|
url$1 += querystringify(options.query);
|
|
66
63
|
}
|
|
67
|
-
if (!options.headers)
|
|
68
|
-
options.headers = {};
|
|
64
|
+
if (!options.headers) options.headers = {};
|
|
69
65
|
const uri = new url.URL(url$1);
|
|
70
66
|
const protocol = uri.protocol === "https:" ? https__default.default : http__default.default;
|
|
71
|
-
if (!uri.protocol)
|
|
72
|
-
throw Error("Unknown protocol");
|
|
67
|
+
if (!uri.protocol) throw Error("Unknown protocol");
|
|
73
68
|
const requestOptions = {
|
|
74
69
|
headers: {},
|
|
75
70
|
host: uri.host ? uri.host.replace(/:[0-9]+$/, "") : uri.host,
|
|
@@ -91,8 +86,7 @@ async function request(url$1, options = { headers: {} }) {
|
|
|
91
86
|
if (body && typeof body !== "string")
|
|
92
87
|
if ((_a = options.headers["Content-Type"]) == null ? void 0 : _a.toString().includes("application/x-www-form-urlencoded"))
|
|
93
88
|
body = querystringify(body);
|
|
94
|
-
else
|
|
95
|
-
body = JSON.stringify(body);
|
|
89
|
+
else body = JSON.stringify(body);
|
|
96
90
|
if (body && !options.headers["Content-Length"])
|
|
97
91
|
requestOptions.headers["Content-Length"] = Buffer.byteLength(body);
|
|
98
92
|
return await new Promise((resolve, reject) => {
|
|
@@ -190,8 +184,7 @@ async function request(url$1, options = { headers: {} }) {
|
|
|
190
184
|
}).on("data", (chunk) => raw.push(chunk));
|
|
191
185
|
}
|
|
192
186
|
);
|
|
193
|
-
if (body)
|
|
194
|
-
req.write(body);
|
|
187
|
+
if (body) req.write(body);
|
|
195
188
|
if (options.file) {
|
|
196
189
|
const crlf = "\r\n";
|
|
197
190
|
const boundary = `--${Math.random().toString(16)}`;
|
package/dist/index.mjs
CHANGED
|
@@ -24,8 +24,7 @@ function querystringify(obj) {
|
|
|
24
24
|
}
|
|
25
25
|
key = encodeURIComponent(key);
|
|
26
26
|
value = encodeURIComponent(value);
|
|
27
|
-
if (key === null || value === null)
|
|
28
|
-
continue;
|
|
27
|
+
if (key === null || value === null) continue;
|
|
29
28
|
pairs.push(`${key}=${value}`);
|
|
30
29
|
}
|
|
31
30
|
}
|
|
@@ -51,18 +50,14 @@ async function request(url, options = { headers: {} }) {
|
|
|
51
50
|
return mock(url, options);
|
|
52
51
|
}
|
|
53
52
|
if (options.query) {
|
|
54
|
-
if (!url.includes("?"))
|
|
55
|
-
|
|
56
|
-
else if (!url.endsWith("?"))
|
|
57
|
-
url += "&";
|
|
53
|
+
if (!url.includes("?")) url += "?";
|
|
54
|
+
else if (!url.endsWith("?")) url += "&";
|
|
58
55
|
url += querystringify(options.query);
|
|
59
56
|
}
|
|
60
|
-
if (!options.headers)
|
|
61
|
-
options.headers = {};
|
|
57
|
+
if (!options.headers) options.headers = {};
|
|
62
58
|
const uri = new URL(url);
|
|
63
59
|
const protocol = uri.protocol === "https:" ? https : http;
|
|
64
|
-
if (!uri.protocol)
|
|
65
|
-
throw Error("Unknown protocol");
|
|
60
|
+
if (!uri.protocol) throw Error("Unknown protocol");
|
|
66
61
|
const requestOptions = {
|
|
67
62
|
headers: {},
|
|
68
63
|
host: uri.host ? uri.host.replace(/:[0-9]+$/, "") : uri.host,
|
|
@@ -84,8 +79,7 @@ async function request(url, options = { headers: {} }) {
|
|
|
84
79
|
if (body && typeof body !== "string")
|
|
85
80
|
if ((_a = options.headers["Content-Type"]) == null ? void 0 : _a.toString().includes("application/x-www-form-urlencoded"))
|
|
86
81
|
body = querystringify(body);
|
|
87
|
-
else
|
|
88
|
-
body = JSON.stringify(body);
|
|
82
|
+
else body = JSON.stringify(body);
|
|
89
83
|
if (body && !options.headers["Content-Length"])
|
|
90
84
|
requestOptions.headers["Content-Length"] = Buffer.byteLength(body);
|
|
91
85
|
return await new Promise((resolve, reject) => {
|
|
@@ -183,8 +177,7 @@ async function request(url, options = { headers: {} }) {
|
|
|
183
177
|
}).on("data", (chunk) => raw.push(chunk));
|
|
184
178
|
}
|
|
185
179
|
);
|
|
186
|
-
if (body)
|
|
187
|
-
req.write(body);
|
|
180
|
+
if (body) req.write(body);
|
|
188
181
|
if (options.file) {
|
|
189
182
|
const crlf = "\r\n";
|
|
190
183
|
const boundary = `--${Math.random().toString(16)}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/request",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@faasjs/logger": "2.
|
|
24
|
+
"@faasjs/logger": "2.4.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@faasjs/logger": "2.
|
|
27
|
+
"@faasjs/logger": "2.4.0"
|
|
28
28
|
},
|
|
29
29
|
"engines": {
|
|
30
30
|
"npm": ">=9.0.0",
|