@wiajs/req 1.7.12 → 1.7.13
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/node/req.cjs +254 -99
- package/dist/req.js +3542 -0
- package/dist/req.min.js +6 -0
- package/dist/web/req.cjs +4025 -0
- package/dist/web/req.mjs +2795 -1356
- package/lib/adapters/http.js +23 -7
- package/package.json +6 -6
- package/dist/node/req.mjs +0 -3550
package/lib/adapters/http.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import request from '@wiajs/request';
|
|
2
|
-
import Agent from '@wiajs/agent';
|
|
2
|
+
import { Agent } from '@wiajs/agent';
|
|
3
3
|
import { log as Log, name } from '@wiajs/log';
|
|
4
4
|
import utils from '../utils.js';
|
|
5
5
|
import settle from '../core/settle.js';
|
|
@@ -24,6 +24,20 @@ import formDataToStream from '../helpers/formDataToStream.js';
|
|
|
24
24
|
import readBlob from '../helpers/readBlob.js';
|
|
25
25
|
import callbackify from '../helpers/callbackify.js';
|
|
26
26
|
import { progressEventReducer, progressEventDecorator, asyncDecorator } from '../helpers/progressEventReducer.js';
|
|
27
|
+
const px = {
|
|
28
|
+
host: '114.98.163.61:17813'
|
|
29
|
+
};
|
|
30
|
+
const agent = {
|
|
31
|
+
// proxy: `http://${px.host}`, // 高效、隧道
|
|
32
|
+
proxy: `socks://${px.host}`,
|
|
33
|
+
// 连接复用,目的主机如关闭,则重新连接,连接代理keepAlive需为true
|
|
34
|
+
keepAlive: true,
|
|
35
|
+
// 同一目的网址最大并发连接,超过排队,隧道代理或服务器限制并发时需设置,否则报错,默认值:Infinity
|
|
36
|
+
// maxSockets: 5, // 无连接,并发连接时,此参数无效,转发代理支持并发无需设置或设置并发数
|
|
37
|
+
// maxFreeSockets: 5, // 同一目的主机空闲最大连接,超过关闭。keepAlive true 时有效。默认值:256
|
|
38
|
+
// timeout: 10000, // 建立连接时长,缺省 30000
|
|
39
|
+
rejectUnauthorized: false
|
|
40
|
+
};
|
|
27
41
|
const log = Log({
|
|
28
42
|
env: `wia:req:${name(import.meta.url)}`
|
|
29
43
|
});
|
|
@@ -248,15 +262,15 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
|
|
|
248
262
|
path,
|
|
249
263
|
method,
|
|
250
264
|
headers: headers.toJSON(),
|
|
251
|
-
agents: {
|
|
252
|
-
|
|
253
|
-
https: config.httpsAgent
|
|
254
|
-
},
|
|
265
|
+
// agents: {http: config.httpAgent, https: config.httpsAgent},
|
|
266
|
+
agents,
|
|
255
267
|
auth,
|
|
256
268
|
protocol,
|
|
257
269
|
family,
|
|
258
270
|
beforeRedirect: dispatchBeforeRedirect,
|
|
259
|
-
beforeRedirects: {}
|
|
271
|
+
beforeRedirects: {},
|
|
272
|
+
http,
|
|
273
|
+
https
|
|
260
274
|
};
|
|
261
275
|
// cacheable-lookup integration hotfix
|
|
262
276
|
if (!utils.isUndefined(lookup)) options.lookup = lookup;
|
|
@@ -270,6 +284,7 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
|
|
|
270
284
|
// 执行请求的具体对象
|
|
271
285
|
_.transport = config.transport;
|
|
272
286
|
const isHttpsRequest = isHttps.test(options.protocol);
|
|
287
|
+
// agents 优先于 agent,在 request中根据协议从 agents 中获取
|
|
273
288
|
options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
|
|
274
289
|
if (config.maxBodyLength > -1) options.maxBodyLength = config.maxBodyLength;
|
|
275
290
|
else options.maxBodyLength = Number.POSITIVE_INFINITY;
|
|
@@ -486,7 +501,8 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
|
|
|
486
501
|
abort(new CanceledError('Request stream has been aborted', config, req));
|
|
487
502
|
}
|
|
488
503
|
});
|
|
489
|
-
data.pipe(req)
|
|
504
|
+
data.pipe(req) // stream 写入数据
|
|
505
|
+
;
|
|
490
506
|
} else req.end(data);
|
|
491
507
|
}
|
|
492
508
|
});
|
package/package.json
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wiajs/req",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.13",
|
|
4
4
|
"description": "Promise And Stream based AXIOS client for the browser and node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"main": "index.js",
|
|
8
|
-
"browser": {
|
|
9
|
-
"./lib/adapters/http.js": "./lib/helpers/null.js",
|
|
10
|
-
"./lib/platform/node/index.js": "./lib/platform/browser/index.js",
|
|
11
|
-
"./lib/platform/node/classes/FormData.js": "./lib/helpers/null.js"
|
|
12
|
-
},
|
|
13
8
|
"exports": {
|
|
14
9
|
".": {
|
|
15
10
|
"types": {
|
|
@@ -38,6 +33,11 @@
|
|
|
38
33
|
"./unsafe/utils.js": "./lib/utils.js",
|
|
39
34
|
"./package.json": "./package.json"
|
|
40
35
|
},
|
|
36
|
+
"browser": {
|
|
37
|
+
"./src/adapters/http.js": "./lib/helpers/null.js",
|
|
38
|
+
"./src/platform/node/index.js": "./lib/platform/browser/index.js",
|
|
39
|
+
"./src/platform/node/classes/FormData.js": "./lib/helpers/null.js"
|
|
40
|
+
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"test": "npm run test:eslint && npm run test:mocha && npm run test:karma && npm run test:dtslint && npm run test:exports",
|
|
43
43
|
"test:eslint": "node bin/ssl_hotfix.js eslint lib/**/*.js",
|