@wiajs/request 3.0.30 → 3.0.32

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/request.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wia request v3.0.30
2
+ * wia request v3.0.32
3
3
  * (c) 2022-2024 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
@@ -805,8 +805,10 @@ class Request extends stream.Duplex {
805
805
  // 'error' 事件处理,避免错误将冒泡到全局导致程序崩溃
806
806
  req.on('error', err => {
807
807
  destroyRequest(req); // 释放资源
808
- log$1.error({errcode: err.code}, 'request');
809
- switch (err.code) {
808
+ // @ts-ignore
809
+ log$1.error({errcode: err?.code}, 'request');
810
+ // @ts-ignore
811
+ switch (err?.code) {
810
812
  case 'ENOTFOUND':
811
813
  m.emit('error', new HostNotfoundError());
812
814
  break
@@ -1674,7 +1676,7 @@ utils.createErrorType(
1674
1676
  const looksLikeBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
1675
1677
  const looksLikeV8 = utils.isFunction(Error.captureStackTrace);
1676
1678
  if (!looksLikeNode && (looksLikeBrowser || !looksLikeV8)) {
1677
- console.warn('The follow-redirects package should be excluded from browser builds.');
1679
+ log.warn('The follow-redirects package should be excluded from browser builds.');
1678
1680
  }
1679
1681
  })();
1680
1682
 
@@ -1734,11 +1736,15 @@ function init(uri, opts, cb) {
1734
1736
  // @ts-ignore
1735
1737
  if (!utils.isString(opts.host) && !utils.isString(opts.hostname)) opts.hostname = '::1';
1736
1738
  // @ts-ignore
1737
- if (opts.method) opts.method = opts.method.toUpperCase();
1739
+ opts.method = (opts.method ?? 'get').toUpperCase();
1738
1740
 
1739
1741
  // @ts-ignore
1740
1742
  // follow-redirects does not skip comparison, so it should always succeed for axios -1 unlimited
1741
1743
  opts.maxBodyLength = opts.maxBodyLength ?? Number.POSITIVE_INFINITY;
1744
+ // @ts-ignore
1745
+ opts.maxRedirects = opts.maxRedirects ?? 21;
1746
+ // @ts-ignore
1747
+ if (opts.maxRedirects === 0) opts.followRedirects = false;
1742
1748
 
1743
1749
  R = {opts, cb};
1744
1750
  // log({R}, 'init')
package/dist/request.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wia request v3.0.30
2
+ * wia request v3.0.32
3
3
  * (c) 2022-2024 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
@@ -802,8 +802,10 @@ class Request extends Duplex {
802
802
  // 'error' 事件处理,避免错误将冒泡到全局导致程序崩溃
803
803
  req.on('error', err => {
804
804
  destroyRequest(req); // 释放资源
805
- log$1.error({errcode: err.code}, 'request');
806
- switch (err.code) {
805
+ // @ts-ignore
806
+ log$1.error({errcode: err?.code}, 'request');
807
+ // @ts-ignore
808
+ switch (err?.code) {
807
809
  case 'ENOTFOUND':
808
810
  m.emit('error', new HostNotfoundError());
809
811
  break
@@ -1671,7 +1673,7 @@ utils.createErrorType(
1671
1673
  const looksLikeBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
1672
1674
  const looksLikeV8 = utils.isFunction(Error.captureStackTrace);
1673
1675
  if (!looksLikeNode && (looksLikeBrowser || !looksLikeV8)) {
1674
- console.warn('The follow-redirects package should be excluded from browser builds.');
1676
+ log.warn('The follow-redirects package should be excluded from browser builds.');
1675
1677
  }
1676
1678
  })();
1677
1679
 
@@ -1731,11 +1733,15 @@ function init(uri, opts, cb) {
1731
1733
  // @ts-ignore
1732
1734
  if (!utils.isString(opts.host) && !utils.isString(opts.hostname)) opts.hostname = '::1';
1733
1735
  // @ts-ignore
1734
- if (opts.method) opts.method = opts.method.toUpperCase();
1736
+ opts.method = (opts.method ?? 'get').toUpperCase();
1735
1737
 
1736
1738
  // @ts-ignore
1737
1739
  // follow-redirects does not skip comparison, so it should always succeed for axios -1 unlimited
1738
1740
  opts.maxBodyLength = opts.maxBodyLength ?? Number.POSITIVE_INFINITY;
1741
+ // @ts-ignore
1742
+ opts.maxRedirects = opts.maxRedirects ?? 21;
1743
+ // @ts-ignore
1744
+ if (opts.maxRedirects === 0) opts.followRedirects = false;
1739
1745
 
1740
1746
  R = {opts, cb};
1741
1747
  // log({R}, 'init')
package/lib/index.js CHANGED
@@ -38,7 +38,7 @@ const log = Log({
38
38
  const looksLikeBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
39
39
  const looksLikeV8 = utils.isFunction(Error.captureStackTrace);
40
40
  if (!looksLikeNode && (looksLikeBrowser || !looksLikeV8)) {
41
- console.warn('The follow-redirects package should be excluded from browser builds.');
41
+ log.warn('The follow-redirects package should be excluded from browser builds.');
42
42
  }
43
43
  })();
44
44
  /**
@@ -92,10 +92,14 @@ const log = Log({
92
92
  // @ts-ignore
93
93
  if (!utils.isString(opts.host) && !utils.isString(opts.hostname)) opts.hostname = '::1';
94
94
  // @ts-ignore
95
- if (opts.method) opts.method = opts.method.toUpperCase();
95
+ opts.method = (opts.method ?? 'get').toUpperCase();
96
96
  // @ts-ignore
97
97
  // follow-redirects does not skip comparison, so it should always succeed for axios -1 unlimited
98
98
  opts.maxBodyLength = opts.maxBodyLength ?? Number.POSITIVE_INFINITY;
99
+ // @ts-ignore
100
+ opts.maxRedirects = opts.maxRedirects ?? 21;
101
+ // @ts-ignore
102
+ if (opts.maxRedirects === 0) opts.followRedirects = false;
99
103
  R = {
100
104
  opts,
101
105
  cb
package/lib/request.js CHANGED
@@ -281,10 +281,12 @@ const ConnResetError = utils.createErrorType('ERR_CONNRESET', '连接被重置
281
281
  req.on('error', (err)=>{
282
282
  destroyRequest(req) // 释放资源
283
283
  ;
284
+ // @ts-ignore
284
285
  log.error({
285
- errcode: err.code
286
+ errcode: err?.code
286
287
  }, 'request');
287
- switch(err.code){
288
+ // @ts-ignore
289
+ switch(err?.code){
288
290
  case 'ENOTFOUND':
289
291
  m.emit('error', new HostNotfoundError());
290
292
  break;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@wiajs/request",
3
3
  "description": "Stream HTTP request client.",
4
4
  "keywords": ["http", "simple", "util", "utility"],
5
- "version": "3.0.30",
5
+ "version": "3.0.32",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "types": "types/index.d.ts",