@faasjs/request 0.0.2-beta.243 → 0.0.2-beta.302
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 +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.es.js +8 -8
- package/lib/index.js +11 -13
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
网络请求库
|
|
4
4
|
|
|
5
|
-
[](https://github.com/faasjs/faasjs/blob/
|
|
5
|
+
[](https://github.com/faasjs/faasjs/blob/main/packages/faasjs/request/LICENSE)
|
|
6
6
|
[](https://www.npmjs.com/package/@faasjs/request)
|
|
7
7
|
[](https://www.npmjs.com/package/@faasjs/request)
|
|
8
8
|
|
package/lib/index.d.ts
CHANGED
|
@@ -56,7 +56,7 @@ export declare function querystringify(obj: any): string;
|
|
|
56
56
|
* 发起网络请求
|
|
57
57
|
* @param {string} url 请求路径或完整网址
|
|
58
58
|
* @param {object=} [options={}] 参数和配置
|
|
59
|
-
* @param {string} [options.
|
|
59
|
+
* @param {string} [options.method=GET] 请求方法
|
|
60
60
|
* @param {object} [options.query={}] 请求参数,放置于 path 后,若需放置在 body 中,请使用 body 参数
|
|
61
61
|
* @param {object} [options.headers={}] 请求头
|
|
62
62
|
* @param {object=} options.body 请求体
|
package/lib/index.es.js
CHANGED
|
@@ -37,7 +37,7 @@ function querystringify(obj) {
|
|
|
37
37
|
* 发起网络请求
|
|
38
38
|
* @param {string} url 请求路径或完整网址
|
|
39
39
|
* @param {object=} [options={}] 参数和配置
|
|
40
|
-
* @param {string} [options.
|
|
40
|
+
* @param {string} [options.method=GET] 请求方法
|
|
41
41
|
* @param {object} [options.query={}] 请求参数,放置于 path 后,若需放置在 body 中,请使用 body 参数
|
|
42
42
|
* @param {object} [options.headers={}] 请求头
|
|
43
43
|
* @param {object=} options.body 请求体
|
|
@@ -77,7 +77,7 @@ async function request(url, { headers, method, query, body, timeout, auth, file,
|
|
|
77
77
|
const uri = new URL(url);
|
|
78
78
|
const protocol = uri.protocol === 'https:' ? https : http;
|
|
79
79
|
if (!uri.protocol)
|
|
80
|
-
throw Error('
|
|
80
|
+
throw Error('Unknown protocol');
|
|
81
81
|
const options = {
|
|
82
82
|
headers: {},
|
|
83
83
|
host: uri.host ? uri.host.replace(/:[0-9]+$/, '') : uri.host,
|
|
@@ -105,7 +105,7 @@ async function request(url, { headers, method, query, body, timeout, auth, file,
|
|
|
105
105
|
if (body && !options.headers['Content-Length'])
|
|
106
106
|
options.headers['Content-Length'] = Buffer.byteLength(body);
|
|
107
107
|
return await new Promise(function (resolve, reject) {
|
|
108
|
-
log.debug('request %
|
|
108
|
+
log.debug('request %j', {
|
|
109
109
|
...options,
|
|
110
110
|
body
|
|
111
111
|
});
|
|
@@ -142,7 +142,7 @@ async function request(url, { headers, method, query, body, timeout, auth, file,
|
|
|
142
142
|
if (response.statusCode >= 200 && response.statusCode < 400)
|
|
143
143
|
resolve(response);
|
|
144
144
|
else {
|
|
145
|
-
log.debug('response.error %
|
|
145
|
+
log.debug('response.error %j', response);
|
|
146
146
|
reject(response);
|
|
147
147
|
}
|
|
148
148
|
});
|
|
@@ -153,19 +153,19 @@ async function request(url, { headers, method, query, body, timeout, auth, file,
|
|
|
153
153
|
if (file) {
|
|
154
154
|
const crlf = '\r\n';
|
|
155
155
|
const boundary = `--${Math.random().toString(16)}`;
|
|
156
|
-
const
|
|
156
|
+
const delimiter = `${crlf}--${boundary}`;
|
|
157
157
|
const headers = [`Content-Disposition: form-data; name="file"; filename="${basename(file)}"${crlf}`];
|
|
158
158
|
const multipartBody = Buffer.concat([
|
|
159
|
-
Buffer.from(
|
|
159
|
+
Buffer.from(delimiter + crlf + headers.join('') + crlf),
|
|
160
160
|
readFileSync(file),
|
|
161
|
-
Buffer.from(`${
|
|
161
|
+
Buffer.from(`${delimiter}--`)
|
|
162
162
|
]);
|
|
163
163
|
req.setHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);
|
|
164
164
|
req.setHeader('Content-Length', multipartBody.length);
|
|
165
165
|
req.write(multipartBody);
|
|
166
166
|
}
|
|
167
167
|
req.on('error', function (e) {
|
|
168
|
-
log.timeEnd(url, 'response.error %
|
|
168
|
+
log.timeEnd(url, 'response.error %j', e);
|
|
169
169
|
reject(e);
|
|
170
170
|
});
|
|
171
171
|
log.time(url);
|
package/lib/index.js
CHANGED
|
@@ -18,14 +18,12 @@ function _interopNamespace(e) {
|
|
|
18
18
|
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
19
|
Object.defineProperty(n, k, d.get ? d : {
|
|
20
20
|
enumerable: true,
|
|
21
|
-
get: function () {
|
|
22
|
-
return e[k];
|
|
23
|
-
}
|
|
21
|
+
get: function () { return e[k]; }
|
|
24
22
|
});
|
|
25
23
|
}
|
|
26
24
|
});
|
|
27
25
|
}
|
|
28
|
-
n[
|
|
26
|
+
n["default"] = e;
|
|
29
27
|
return Object.freeze(n);
|
|
30
28
|
}
|
|
31
29
|
|
|
@@ -64,7 +62,7 @@ function querystringify(obj) {
|
|
|
64
62
|
* 发起网络请求
|
|
65
63
|
* @param {string} url 请求路径或完整网址
|
|
66
64
|
* @param {object=} [options={}] 参数和配置
|
|
67
|
-
* @param {string} [options.
|
|
65
|
+
* @param {string} [options.method=GET] 请求方法
|
|
68
66
|
* @param {object} [options.query={}] 请求参数,放置于 path 后,若需放置在 body 中,请使用 body 参数
|
|
69
67
|
* @param {object} [options.headers={}] 请求头
|
|
70
68
|
* @param {object=} options.body 请求体
|
|
@@ -104,7 +102,7 @@ async function request(url$1, { headers, method, query, body, timeout, auth, fil
|
|
|
104
102
|
const uri = new url.URL(url$1);
|
|
105
103
|
const protocol = uri.protocol === 'https:' ? https__namespace : http__namespace;
|
|
106
104
|
if (!uri.protocol)
|
|
107
|
-
throw Error('
|
|
105
|
+
throw Error('Unknown protocol');
|
|
108
106
|
const options = {
|
|
109
107
|
headers: {},
|
|
110
108
|
host: uri.host ? uri.host.replace(/:[0-9]+$/, '') : uri.host,
|
|
@@ -132,7 +130,7 @@ async function request(url$1, { headers, method, query, body, timeout, auth, fil
|
|
|
132
130
|
if (body && !options.headers['Content-Length'])
|
|
133
131
|
options.headers['Content-Length'] = Buffer.byteLength(body);
|
|
134
132
|
return await new Promise(function (resolve, reject) {
|
|
135
|
-
log.debug('request %
|
|
133
|
+
log.debug('request %j', {
|
|
136
134
|
...options,
|
|
137
135
|
body
|
|
138
136
|
});
|
|
@@ -169,7 +167,7 @@ async function request(url$1, { headers, method, query, body, timeout, auth, fil
|
|
|
169
167
|
if (response.statusCode >= 200 && response.statusCode < 400)
|
|
170
168
|
resolve(response);
|
|
171
169
|
else {
|
|
172
|
-
log.debug('response.error %
|
|
170
|
+
log.debug('response.error %j', response);
|
|
173
171
|
reject(response);
|
|
174
172
|
}
|
|
175
173
|
});
|
|
@@ -180,19 +178,19 @@ async function request(url$1, { headers, method, query, body, timeout, auth, fil
|
|
|
180
178
|
if (file) {
|
|
181
179
|
const crlf = '\r\n';
|
|
182
180
|
const boundary = `--${Math.random().toString(16)}`;
|
|
183
|
-
const
|
|
181
|
+
const delimiter = `${crlf}--${boundary}`;
|
|
184
182
|
const headers = [`Content-Disposition: form-data; name="file"; filename="${path.basename(file)}"${crlf}`];
|
|
185
183
|
const multipartBody = Buffer.concat([
|
|
186
|
-
Buffer.from(
|
|
184
|
+
Buffer.from(delimiter + crlf + headers.join('') + crlf),
|
|
187
185
|
fs.readFileSync(file),
|
|
188
|
-
Buffer.from(`${
|
|
186
|
+
Buffer.from(`${delimiter}--`)
|
|
189
187
|
]);
|
|
190
188
|
req.setHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);
|
|
191
189
|
req.setHeader('Content-Length', multipartBody.length);
|
|
192
190
|
req.write(multipartBody);
|
|
193
191
|
}
|
|
194
192
|
req.on('error', function (e) {
|
|
195
|
-
log.timeEnd(url$1, 'response.error %
|
|
193
|
+
log.timeEnd(url$1, 'response.error %j', e);
|
|
196
194
|
reject(e);
|
|
197
195
|
});
|
|
198
196
|
log.time(url$1);
|
|
@@ -200,7 +198,7 @@ async function request(url$1, { headers, method, query, body, timeout, auth, fil
|
|
|
200
198
|
});
|
|
201
199
|
}
|
|
202
200
|
|
|
203
|
-
exports[
|
|
201
|
+
exports["default"] = request;
|
|
204
202
|
exports.querystringify = querystringify;
|
|
205
203
|
exports.request = request;
|
|
206
204
|
exports.setMock = setMock;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/request",
|
|
3
|
-
"version": "0.0.2-beta.
|
|
3
|
+
"version": "0.0.2-beta.302",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.es.js",
|
|
@@ -11,13 +11,17 @@
|
|
|
11
11
|
"url": "git+https://github.com/faasjs/faasjs.git",
|
|
12
12
|
"directory": "packages/request"
|
|
13
13
|
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/faasjs/faasjs/issues"
|
|
16
|
+
},
|
|
17
|
+
"funding": "https://github.com/sponsors/faasjs",
|
|
14
18
|
"scripts": {
|
|
15
19
|
"prepack": "rm -rf ./lib && rollup -c && mv lib/*/src/* lib/"
|
|
16
20
|
},
|
|
17
21
|
"files": [
|
|
18
22
|
"lib"
|
|
19
23
|
],
|
|
20
|
-
"
|
|
24
|
+
"peerDependencies": {
|
|
21
25
|
"@faasjs/logger": "^0.0.2-beta.243"
|
|
22
26
|
},
|
|
23
27
|
"devDependencies": {
|
|
@@ -28,5 +32,8 @@
|
|
|
28
32
|
"rollup-plugin-typescript2": "*",
|
|
29
33
|
"typescript": "*"
|
|
30
34
|
},
|
|
31
|
-
"
|
|
35
|
+
"engines": {
|
|
36
|
+
"npm": ">=8.0.0"
|
|
37
|
+
},
|
|
38
|
+
"gitHead": "b53fb35a91369afd0185fb555d98e5c9d90b54bd"
|
|
32
39
|
}
|