@wiajs/req 1.7.11 → 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 -101
- package/dist/req.js +1626 -20285
- package/dist/req.min.js +2 -2
- package/dist/web/req.cjs +1702 -20719
- package/dist/web/req.mjs +2795 -1356
- package/index.d.cts +7 -3
- package/index.d.ts +7 -3
- package/lib/adapters/http.js +23 -8
- package/package.json +9 -9
- package/dist/node/req.mjs +0 -3550
package/index.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type Agent, {AgentOpts} from '@wiajs/agent';
|
|
2
|
+
|
|
1
3
|
interface RawAxiosHeaders {
|
|
2
4
|
[key: string]: axios.AxiosHeaderValue;
|
|
3
5
|
}
|
|
@@ -123,11 +125,11 @@ declare class Axios {
|
|
|
123
125
|
};
|
|
124
126
|
getUri(config?: axios.AxiosRequestConfig): string;
|
|
125
127
|
request<T = any, R = axios.AxiosResponse<T>, D = any>(config: axios.AxiosRequestConfig<D>): Promise<R>;
|
|
126
|
-
get<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
|
128
|
+
get<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, param?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
|
129
|
+
post<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
|
127
130
|
delete<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
|
128
131
|
head<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
|
129
132
|
options<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
|
130
|
-
post<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
|
131
133
|
put<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
|
132
134
|
patch<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
|
133
135
|
postForm<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
|
@@ -403,7 +405,8 @@ declare namespace axios {
|
|
|
403
405
|
transport?: any;
|
|
404
406
|
httpAgent?: any;
|
|
405
407
|
httpsAgent?: any;
|
|
406
|
-
|
|
408
|
+
agent?: AgentOpts;
|
|
409
|
+
agents?: Agent;
|
|
407
410
|
cancelToken?: CancelToken;
|
|
408
411
|
decompress?: boolean;
|
|
409
412
|
transitional?: TransitionalOptions;
|
|
@@ -450,6 +453,7 @@ declare namespace axios {
|
|
|
450
453
|
}
|
|
451
454
|
|
|
452
455
|
interface AxiosResponse<T = any, D = any> {
|
|
456
|
+
body: T;
|
|
453
457
|
data: T;
|
|
454
458
|
status: number;
|
|
455
459
|
statusText: string;
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type Agent, {AgentOpts} from '@wiajs/agent';
|
|
2
|
+
|
|
1
3
|
// TypeScript Version: 4.7
|
|
2
4
|
export type AxiosHeaderValue = AxiosHeaders | string | string[] | number | boolean | null;
|
|
3
5
|
|
|
@@ -344,7 +346,8 @@ export interface AxiosRequestConfig<D = any> {
|
|
|
344
346
|
transport?: any;
|
|
345
347
|
httpAgent?: any;
|
|
346
348
|
httpsAgent?: any;
|
|
347
|
-
|
|
349
|
+
agent?: AgentOpts;
|
|
350
|
+
agents?: Agent;
|
|
348
351
|
cancelToken?: CancelToken;
|
|
349
352
|
decompress?: boolean;
|
|
350
353
|
transitional?: TransitionalOptions;
|
|
@@ -391,6 +394,7 @@ export interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>
|
|
|
391
394
|
}
|
|
392
395
|
|
|
393
396
|
export interface AxiosResponse<T = any, D = any> {
|
|
397
|
+
body: T;
|
|
394
398
|
data: T;
|
|
395
399
|
status: number;
|
|
396
400
|
statusText: string;
|
|
@@ -491,11 +495,11 @@ export class Axios {
|
|
|
491
495
|
};
|
|
492
496
|
getUri(config?: AxiosRequestConfig): string;
|
|
493
497
|
request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
|
|
494
|
-
get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
498
|
+
get<T = any, R = AxiosResponse<T>, D = any>(url: string, param?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
499
|
+
post<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
495
500
|
delete<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
496
501
|
head<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
497
502
|
options<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
498
|
-
post<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
499
503
|
put<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
500
504
|
patch<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
501
505
|
postForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
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,7 +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
|
-
|
|
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
|
+
};
|
|
28
41
|
const log = Log({
|
|
29
42
|
env: `wia:req:${name(import.meta.url)}`
|
|
30
43
|
});
|
|
@@ -249,15 +262,15 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
|
|
|
249
262
|
path,
|
|
250
263
|
method,
|
|
251
264
|
headers: headers.toJSON(),
|
|
252
|
-
agents: {
|
|
253
|
-
|
|
254
|
-
https: config.httpsAgent
|
|
255
|
-
},
|
|
265
|
+
// agents: {http: config.httpAgent, https: config.httpsAgent},
|
|
266
|
+
agents,
|
|
256
267
|
auth,
|
|
257
268
|
protocol,
|
|
258
269
|
family,
|
|
259
270
|
beforeRedirect: dispatchBeforeRedirect,
|
|
260
|
-
beforeRedirects: {}
|
|
271
|
+
beforeRedirects: {},
|
|
272
|
+
http,
|
|
273
|
+
https
|
|
261
274
|
};
|
|
262
275
|
// cacheable-lookup integration hotfix
|
|
263
276
|
if (!utils.isUndefined(lookup)) options.lookup = lookup;
|
|
@@ -271,6 +284,7 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
|
|
|
271
284
|
// 执行请求的具体对象
|
|
272
285
|
_.transport = config.transport;
|
|
273
286
|
const isHttpsRequest = isHttps.test(options.protocol);
|
|
287
|
+
// agents 优先于 agent,在 request中根据协议从 agents 中获取
|
|
274
288
|
options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
|
|
275
289
|
if (config.maxBodyLength > -1) options.maxBodyLength = config.maxBodyLength;
|
|
276
290
|
else options.maxBodyLength = Number.POSITIVE_INFINITY;
|
|
@@ -487,7 +501,8 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
|
|
|
487
501
|
abort(new CanceledError('Request stream has been aborted', config, req));
|
|
488
502
|
}
|
|
489
503
|
});
|
|
490
|
-
data.pipe(req)
|
|
504
|
+
data.pipe(req) // stream 写入数据
|
|
505
|
+
;
|
|
491
506
|
} else req.end(data);
|
|
492
507
|
}
|
|
493
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",
|
|
@@ -142,9 +142,9 @@
|
|
|
142
142
|
"@rollup/plugin-alias": "^5.1.0"
|
|
143
143
|
},
|
|
144
144
|
"dependencies": {
|
|
145
|
-
"@wiajs/log": "^4.3.
|
|
146
|
-
"@wiajs/request": "^3.0.
|
|
147
|
-
"@wiajs/agent": "^1.0.
|
|
145
|
+
"@wiajs/log": "^4.3.19",
|
|
146
|
+
"@wiajs/request": "^3.0.20",
|
|
147
|
+
"@wiajs/agent": "^1.0.19",
|
|
148
148
|
"form-data": "^4.0.0",
|
|
149
149
|
"proxy-from-env": "^1.1.0"
|
|
150
150
|
},
|