@wiajs/req 1.7.22 → 1.7.25

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @wia/req v1.7.22
2
+ * @wia/req v1.7.25
3
3
  * (c) 2024 Sibyl Yu, Matt Zabriskie and contributors
4
4
  * Released under the MIT License.
5
5
  */
@@ -2917,8 +2917,14 @@ class HttpAdapter {
2917
2917
 
2918
2918
  if (config.httpAgent) options.agents = {http: config.httpAgent};
2919
2919
  if (config.httpsAgent) options.agents.https = config.httpAgent;
2920
- // ! 配置了 agent,使用Agent,否则使用缺省 agent
2921
- if (config.agent) options.agents = new agent.Agent(config.agent);
2920
+
2921
+ // ! 配置了 agent,使用Agent,否则使用缺省 agent,agents 优于agent
2922
+ if (config.agents) options.agents = config.agents;
2923
+ else if (config.agent) options.agents = new agent.Agent(config.agent);
2924
+
2925
+ const isHttpsRequest = isHttps.test(options.protocol);
2926
+ // agents 优先于 agent,在 request中根据协议从 agents 中获取
2927
+ options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
2922
2928
 
2923
2929
  // cacheable-lookup integration hotfix
2924
2930
  if (!utils$1.isUndefined(lookup)) options.lookup = lookup;
@@ -2933,11 +2939,6 @@ class HttpAdapter {
2933
2939
 
2934
2940
  // 执行请求的具体对象
2935
2941
  _.transport = config.transport;
2936
-
2937
- const isHttpsRequest = isHttps.test(options.protocol);
2938
- // agents 优先于 agent,在 request中根据协议从 agents 中获取
2939
- options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
2940
-
2941
2942
  if (config.maxBodyLength > -1) options.maxBodyLength = config.maxBodyLength;
2942
2943
  // follow-redirects does not skip comparison, so it should always succeed for axios -1 unlimited
2943
2944
  else options.maxBodyLength = Number.POSITIVE_INFINITY;
@@ -2947,13 +2948,17 @@ class HttpAdapter {
2947
2948
  // 自动跳转
2948
2949
  // else {
2949
2950
  // 支持跳转或stream,需使用 http、https 封装类
2950
- if (config.maxRedirects) options.maxRedirects = config.maxRedirects;
2951
+
2952
+ options.maxRedirects = config.maxRedirects ?? 21;
2953
+ options.followRedirects = config.followRedirects ?? true; // 默认自动跳转
2954
+ if (config.maxRedirects === 0) options.followRedirects = false;
2951
2955
  if (config.beforeRedirect) options.beforeRedirects.config = config.beforeRedirect;
2952
2956
 
2953
2957
  if (config.insecureHTTPParser) options.insecureHTTPParser = config.insecureHTTPParser;
2954
2958
 
2959
+ // _.data = data
2960
+ options.data = data; // 传给 request 处理
2955
2961
  _.options = options;
2956
- _.data = data;
2957
2962
 
2958
2963
  // log({config}, 'init')
2959
2964
  return options
@@ -2975,7 +2980,7 @@ class HttpAdapter {
2975
2980
  try {
2976
2981
  await _.init();
2977
2982
 
2978
- const {transport, protocol, config, options, data, abort, emitter, maxDownloadRate} = _;
2983
+ const {transport, protocol, config, options, abort, emitter, maxDownloadRate} = _;
2979
2984
  const {responseType, responseEncoding, onDownloadProgress} = config;
2980
2985
 
2981
2986
  if (protocol === 'data:') {
@@ -3060,15 +3065,15 @@ class HttpAdapter {
3060
3065
  }
3061
3066
  );
3062
3067
 
3068
+ // socket 连接成功事件,移到 request
3063
3069
  // set tcp keep alive to prevent drop connection by peer
3064
- req.on(
3065
- 'socket',
3066
- /** @param {*} socket */ socket => {
3067
- // log('onsocket')
3068
- // default interval of sending ack packet is 1 minute
3069
- socket.setKeepAlive(true, 1000 * 60);
3070
- }
3071
- );
3070
+ // req.on(
3071
+ // 'socket',
3072
+ // /** @param {*} socket */ socket => {
3073
+ // // default interval of sending ack packet is 1 minute
3074
+ // socket.setKeepAlive(true, 1000 * 60)
3075
+ // }
3076
+ // )
3072
3077
 
3073
3078
  // Handle request timeout
3074
3079
  if (config.timeout) {
@@ -3237,7 +3242,7 @@ class HttpAdapter {
3237
3242
  }
3238
3243
  );
3239
3244
 
3240
- // 非stream模式需发送数据,由request处理
3245
+ // 非stream模式需发送数据,改由request处理
3241
3246
  // if (utils.isStream(data)) {
3242
3247
  // // Send the request
3243
3248
  // let ended = false
package/dist/req.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @wia/req v1.7.22
2
+ * @wia/req v1.7.25
3
3
  * (c) 2024 Sibyl Yu, Matt Zabriskie and contributors
4
4
  * Released under the MIT License.
5
5
  */
package/dist/req.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @wia/req v1.7.22
2
+ * @wia/req v1.7.25
3
3
  * (c) 2024 Sibyl Yu, Matt Zabriskie and contributors
4
4
  * Released under the MIT License.
5
5
  */
package/dist/web/req.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @wia/req v1.7.22
2
+ * @wia/req v1.7.25
3
3
  * (c) 2024 Sibyl Yu, Matt Zabriskie and contributors
4
4
  * Released under the MIT License.
5
5
  */
package/dist/web/req.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @wia/req v1.7.22
2
+ * @wia/req v1.7.25
3
3
  * (c) 2024 Sibyl Yu, Matt Zabriskie and contributors
4
4
  * Released under the MIT License.
5
5
  */
package/index.d.cts CHANGED
@@ -497,6 +497,7 @@ declare namespace axios {
497
497
  validateStatus?: ((status: number) => boolean) | null
498
498
  maxBodyLength?: number
499
499
  maxRedirects?: number
500
+ followRedirects?: boolean
500
501
  maxRate?: number | [MaxUploadRate, MaxDownloadRate]
501
502
  beforeRedirect?: (
502
503
  options: Record<string, any>,
package/index.d.ts CHANGED
@@ -391,6 +391,7 @@ export interface AxiosRequestConfig<D = any> {
391
391
  validateStatus?: ((status: number) => boolean) | null
392
392
  maxBodyLength?: number
393
393
  maxRedirects?: number
394
+ followRedirects?: boolean
394
395
  maxRate?: number | [MaxUploadRate, MaxDownloadRate]
395
396
  beforeRedirect?: (
396
397
  options: Record<string, any>,
@@ -272,8 +272,12 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
272
272
  http: config.httpAgent
273
273
  };
274
274
  if (config.httpsAgent) options.agents.https = config.httpAgent;
275
- // ! 配置了 agent,使用Agent,否则使用缺省 agent
276
- if (config.agent) options.agents = new Agent(config.agent);
275
+ // ! 配置了 agent,使用Agent,否则使用缺省 agent,agents 优于agent
276
+ if (config.agents) options.agents = config.agents;
277
+ else if (config.agent) options.agents = new Agent(config.agent);
278
+ const isHttpsRequest = isHttps.test(options.protocol);
279
+ // agents 优先于 agent,在 request中根据协议从 agents 中获取
280
+ options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
277
281
  // cacheable-lookup integration hotfix
278
282
  if (!utils.isUndefined(lookup)) options.lookup = lookup;
279
283
  if (config.socketPath) options.socketPath = config.socketPath;
@@ -283,9 +287,6 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
283
287
  }
284
288
  // 执行请求的具体对象
285
289
  _.transport = config.transport;
286
- const isHttpsRequest = isHttps.test(options.protocol);
287
- // agents 优先于 agent,在 request中根据协议从 agents 中获取
288
- options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
289
290
  if (config.maxBodyLength > -1) options.maxBodyLength = config.maxBodyLength;
290
291
  else options.maxBodyLength = Number.POSITIVE_INFINITY;
291
292
  // maxRedirects 缺省 21,不跳转,直接使用系统http or https,不支持 stream
@@ -293,11 +294,16 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
293
294
  // 自动跳转
294
295
  // else {
295
296
  // 支持跳转或stream,需使用 http、https 封装类
296
- if (config.maxRedirects) options.maxRedirects = config.maxRedirects;
297
+ options.maxRedirects = config.maxRedirects ?? 21;
298
+ options.followRedirects = config.followRedirects ?? true // 默认自动跳转
299
+ ;
300
+ if (config.maxRedirects === 0) options.followRedirects = false;
297
301
  if (config.beforeRedirect) options.beforeRedirects.config = config.beforeRedirect;
298
302
  if (config.insecureHTTPParser) options.insecureHTTPParser = config.insecureHTTPParser;
303
+ // _.data = data
304
+ options.data = data // 传给 request 处理
305
+ ;
299
306
  _.options = options;
300
- _.data = data;
301
307
  // log({config}, 'init')
302
308
  return options;
303
309
  }
@@ -313,7 +319,7 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
313
319
  const _ = this;
314
320
  try {
315
321
  await _.init();
316
- const { transport, protocol, config, options, data, abort, emitter, maxDownloadRate } = _;
322
+ const { transport, protocol, config, options, abort, emitter, maxDownloadRate } = _;
317
323
  const { responseType, responseEncoding, onDownloadProgress } = config;
318
324
  if (protocol === 'data:') {
319
325
  /** @type {*} */ let convertedData;
@@ -371,12 +377,15 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
371
377
  // if (req.aborted && err.code !== AxiosError.ERR_FR_TOO_MANY_REDIRECTS) return;
372
378
  reject(AxiosError.from(err, null, config, req));
373
379
  });
380
+ // socket 连接成功事件,移到 request
374
381
  // set tcp keep alive to prevent drop connection by peer
375
- req.on('socket', /** @param {*} socket */ (socket)=>{
376
- // log('onsocket')
377
- // default interval of sending ack packet is 1 minute
378
- socket.setKeepAlive(true, 1000 * 60);
379
- });
382
+ // req.on(
383
+ // 'socket',
384
+ // /** @param {*} socket */ socket => {
385
+ // // default interval of sending ack packet is 1 minute
386
+ // socket.setKeepAlive(true, 1000 * 60)
387
+ // }
388
+ // )
380
389
  // Handle request timeout
381
390
  if (config.timeout) {
382
391
  // This is forcing a int timeout to avoid problems if the `req` interface doesn't handle other types.
@@ -482,7 +491,7 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
482
491
  }
483
492
  });
484
493
  });
485
- // 非stream模式需发送数据,由request处理
494
+ // 非stream模式需发送数据,改由request处理
486
495
  // if (utils.isStream(data)) {
487
496
  // // Send the request
488
497
  // let ended = false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wiajs/req",
3
- "version": "1.7.22",
3
+ "version": "1.7.25",
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",
@@ -143,7 +143,7 @@
143
143
  },
144
144
  "dependencies": {
145
145
  "@wiajs/log": "^4.3.19",
146
- "@wiajs/request": "^3.0.29",
146
+ "@wiajs/request": "^3.0.31",
147
147
  "@wiajs/agent": "^1.0.21",
148
148
  "form-data": "^4.0.0",
149
149
  "proxy-from-env": "^1.1.0"