@wiajs/request 3.0.22 → 3.0.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/request.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wia request v3.0.22
2
+ * wia request v3.0.25
3
3
  * (c) 2022-2024 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
@@ -519,7 +519,7 @@ const writeProps = [
519
519
  const writeMethods = ['cork', 'flushHeaders', 'setNoDelay', 'setSocketKeepAlive'];
520
520
 
521
521
  // Create handlers that pass events from native requests
522
- // 在 clientRequest 事件转发
522
+ // 在 clientRequest 事件转发写事件
523
523
  const writeEvents = [
524
524
  // 'abort', // 弃用
525
525
  // 'aborted', // 弃用
@@ -543,7 +543,7 @@ const writeEventEmit = Object.create(null);
543
543
  for (const ev of writeEvents)
544
544
  writeEventEmit[ev] = /** @param {...any} args */ function (...args) {
545
545
  const m = this; // 事件回调,this === clientRequest 实例
546
- log$1('req event', {ev});
546
+ // log('req event', {ev})
547
547
  m.redirectReq.emit(ev, ...args); // req 事情映射到 redirectReq 上触发
548
548
  };
549
549
 
@@ -554,7 +554,7 @@ const readEventEmit = Object.create(null);
554
554
  for (const ev of readEvents)
555
555
  readEventEmit[ev] = /** @param {...any} args */ function (...args) {
556
556
  const m = this; // 事件回调,this === clientRequest 实例
557
- log$1('res event', {ev});
557
+ // log('res event', {ev})
558
558
  m.redirectReq.emit(ev, ...args); // 向上触发事件
559
559
  };
560
560
 
@@ -661,7 +661,7 @@ class Request extends stream.Duplex {
661
661
  for (const method of writeMethods) {
662
662
  // @ts-ignore
663
663
  m[method] = (a, b) => {
664
- log$1(method, {a, b});
664
+ // log(method, {a, b})
665
665
  // @ts-ignore
666
666
  m._currentRequest?.[method](a, b);
667
667
  };
@@ -674,7 +674,7 @@ class Request extends stream.Duplex {
674
674
  get() {
675
675
  // @ts-ignore
676
676
  const val = m._currentRequest?.[property];
677
- log$1('get property', {property});
677
+ // log('get property', {property})
678
678
  return val
679
679
  },
680
680
  });
@@ -765,7 +765,7 @@ class Request extends stream.Duplex {
765
765
  const httpModule = httpModules[protocol];
766
766
  if (!httpModule) throw TypeError(`Unsupported protocol: ${protocol}`)
767
767
 
768
- log$1({opt, protocol}, 'request');
768
+ // log({opt, protocol}, 'request')
769
769
  // Create the native request and set up its event handlers
770
770
  // @ts-ignore
771
771
  const req = httpModule.request(opt, m._onResponse);
@@ -859,7 +859,7 @@ class Request extends stream.Duplex {
859
859
  */
860
860
  write(chunk, encoding, cb) {
861
861
  const m = this;
862
- log$1({data: chunk, encoding, cb}, 'write');
862
+ // log({data: chunk, encoding, cb}, 'write')
863
863
 
864
864
  // Writing is not allowed if end has been called
865
865
  if (m._ending) throw new WriteAfterEndError()
@@ -1120,7 +1120,7 @@ class Request extends stream.Duplex {
1120
1120
  // If the response is not a redirect; return it as-is
1121
1121
  const {location} = response.headers;
1122
1122
 
1123
- log$1({statusCode, headers: response.headers}, 'processResponse');
1123
+ // log({statusCode, headers: response.headers}, 'processResponse')
1124
1124
 
1125
1125
  if (!location || opt.followRedirects === false || statusCode < 300 || statusCode >= 400) {
1126
1126
  // 非重定向,返回给原始回调处理
@@ -1208,7 +1208,9 @@ class Request extends stream.Duplex {
1208
1208
 
1209
1209
  // Create the redirected request
1210
1210
  const redirectUrl = utils.resolveUrl(location, currentUrl);
1211
+
1211
1212
  log$1({redirectUrl}, 'redirecting to');
1213
+
1212
1214
  m._isRedirect = true;
1213
1215
  // 覆盖原 url 解析部分,包括 protocol、hostname、port等
1214
1216
  utils.spreadUrlObject(redirectUrl, m.opt);
@@ -1256,11 +1258,11 @@ class Request extends stream.Duplex {
1256
1258
  // 'transfer-encoding': 'chunked'时,无content-length,axios v1.2 不能自动解压
1257
1259
  const responseLength = +res.headers['content-length'];
1258
1260
 
1259
- log$1('processStream', {
1260
- statusCode: res.statusCode,
1261
- responseLength,
1262
- headers: res.headers,
1263
- });
1261
+ // log('processStream', {
1262
+ // statusCode: res.statusCode,
1263
+ // responseLength,
1264
+ // headers: res.headers,
1265
+ // })
1264
1266
 
1265
1267
  if (opt.transformStream) {
1266
1268
  opt.transformStream.responseLength = responseLength;
package/dist/request.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wia request v3.0.22
2
+ * wia request v3.0.25
3
3
  * (c) 2022-2024 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
@@ -516,7 +516,7 @@ const writeProps = [
516
516
  const writeMethods = ['cork', 'flushHeaders', 'setNoDelay', 'setSocketKeepAlive'];
517
517
 
518
518
  // Create handlers that pass events from native requests
519
- // 在 clientRequest 事件转发
519
+ // 在 clientRequest 事件转发写事件
520
520
  const writeEvents = [
521
521
  // 'abort', // 弃用
522
522
  // 'aborted', // 弃用
@@ -540,7 +540,7 @@ const writeEventEmit = Object.create(null);
540
540
  for (const ev of writeEvents)
541
541
  writeEventEmit[ev] = /** @param {...any} args */ function (...args) {
542
542
  const m = this; // 事件回调,this === clientRequest 实例
543
- log$1('req event', {ev});
543
+ // log('req event', {ev})
544
544
  m.redirectReq.emit(ev, ...args); // req 事情映射到 redirectReq 上触发
545
545
  };
546
546
 
@@ -551,7 +551,7 @@ const readEventEmit = Object.create(null);
551
551
  for (const ev of readEvents)
552
552
  readEventEmit[ev] = /** @param {...any} args */ function (...args) {
553
553
  const m = this; // 事件回调,this === clientRequest 实例
554
- log$1('res event', {ev});
554
+ // log('res event', {ev})
555
555
  m.redirectReq.emit(ev, ...args); // 向上触发事件
556
556
  };
557
557
 
@@ -658,7 +658,7 @@ class Request extends Duplex {
658
658
  for (const method of writeMethods) {
659
659
  // @ts-ignore
660
660
  m[method] = (a, b) => {
661
- log$1(method, {a, b});
661
+ // log(method, {a, b})
662
662
  // @ts-ignore
663
663
  m._currentRequest?.[method](a, b);
664
664
  };
@@ -671,7 +671,7 @@ class Request extends Duplex {
671
671
  get() {
672
672
  // @ts-ignore
673
673
  const val = m._currentRequest?.[property];
674
- log$1('get property', {property});
674
+ // log('get property', {property})
675
675
  return val
676
676
  },
677
677
  });
@@ -762,7 +762,7 @@ class Request extends Duplex {
762
762
  const httpModule = httpModules[protocol];
763
763
  if (!httpModule) throw TypeError(`Unsupported protocol: ${protocol}`)
764
764
 
765
- log$1({opt, protocol}, 'request');
765
+ // log({opt, protocol}, 'request')
766
766
  // Create the native request and set up its event handlers
767
767
  // @ts-ignore
768
768
  const req = httpModule.request(opt, m._onResponse);
@@ -856,7 +856,7 @@ class Request extends Duplex {
856
856
  */
857
857
  write(chunk, encoding, cb) {
858
858
  const m = this;
859
- log$1({data: chunk, encoding, cb}, 'write');
859
+ // log({data: chunk, encoding, cb}, 'write')
860
860
 
861
861
  // Writing is not allowed if end has been called
862
862
  if (m._ending) throw new WriteAfterEndError()
@@ -1117,7 +1117,7 @@ class Request extends Duplex {
1117
1117
  // If the response is not a redirect; return it as-is
1118
1118
  const {location} = response.headers;
1119
1119
 
1120
- log$1({statusCode, headers: response.headers}, 'processResponse');
1120
+ // log({statusCode, headers: response.headers}, 'processResponse')
1121
1121
 
1122
1122
  if (!location || opt.followRedirects === false || statusCode < 300 || statusCode >= 400) {
1123
1123
  // 非重定向,返回给原始回调处理
@@ -1205,7 +1205,9 @@ class Request extends Duplex {
1205
1205
 
1206
1206
  // Create the redirected request
1207
1207
  const redirectUrl = utils.resolveUrl(location, currentUrl);
1208
+
1208
1209
  log$1({redirectUrl}, 'redirecting to');
1210
+
1209
1211
  m._isRedirect = true;
1210
1212
  // 覆盖原 url 解析部分,包括 protocol、hostname、port等
1211
1213
  utils.spreadUrlObject(redirectUrl, m.opt);
@@ -1253,11 +1255,11 @@ class Request extends Duplex {
1253
1255
  // 'transfer-encoding': 'chunked'时,无content-length,axios v1.2 不能自动解压
1254
1256
  const responseLength = +res.headers['content-length'];
1255
1257
 
1256
- log$1('processStream', {
1257
- statusCode: res.statusCode,
1258
- responseLength,
1259
- headers: res.headers,
1260
- });
1258
+ // log('processStream', {
1259
+ // statusCode: res.statusCode,
1260
+ // responseLength,
1261
+ // headers: res.headers,
1262
+ // })
1261
1263
 
1262
1264
  if (opt.transformStream) {
1263
1265
  opt.transformStream.responseLength = responseLength;
package/lib/request.js CHANGED
@@ -81,7 +81,7 @@ const writeMethods = [
81
81
  'setSocketKeepAlive'
82
82
  ];
83
83
  // Create handlers that pass events from native requests
84
- // 在 clientRequest 事件转发
84
+ // 在 clientRequest 事件转发写事件
85
85
  const writeEvents = [
86
86
  // 'abort', // 弃用
87
87
  // 'aborted', // 弃用
@@ -103,9 +103,7 @@ const writeEventEmit = Object.create(null);
103
103
  for (const ev of writeEvents)writeEventEmit[ev] = /** @param {...any} args */ function(...args) {
104
104
  const m = this // 事件回调,this === clientRequest 实例
105
105
  ;
106
- log('req event', {
107
- ev
108
- });
106
+ // log('req event', {ev})
109
107
  m.redirectReq.emit(ev, ...args) // req 事情映射到 redirectReq 上触发
110
108
  ;
111
109
  };
@@ -123,9 +121,7 @@ const readEventEmit = Object.create(null);
123
121
  for (const ev of readEvents)readEventEmit[ev] = /** @param {...any} args */ function(...args) {
124
122
  const m = this // 事件回调,this === clientRequest 实例
125
123
  ;
126
- log('res event', {
127
- ev
128
- });
124
+ // log('res event', {ev})
129
125
  m.redirectReq.emit(ev, ...args) // 向上触发事件
130
126
  ;
131
127
  };
@@ -178,10 +174,7 @@ const WriteAfterEndError = utils.createErrorType('ERR_STREAM_WRITE_AFTER_END', '
178
174
  for (const method of writeMethods){
179
175
  // @ts-ignore
180
176
  m[method] = (a, b)=>{
181
- log(method, {
182
- a,
183
- b
184
- });
177
+ // log(method, {a, b})
185
178
  // @ts-ignore
186
179
  m._currentRequest?.[method](a, b);
187
180
  };
@@ -193,9 +186,7 @@ const WriteAfterEndError = utils.createErrorType('ERR_STREAM_WRITE_AFTER_END', '
193
186
  get () {
194
187
  // @ts-ignore
195
188
  const val = m._currentRequest?.[property];
196
- log('get property', {
197
- property
198
- });
189
+ // log('get property', {property})
199
190
  return val;
200
191
  }
201
192
  });
@@ -265,10 +256,7 @@ const WriteAfterEndError = utils.createErrorType('ERR_STREAM_WRITE_AFTER_END', '
265
256
  }
266
257
  const httpModule = httpModules[protocol];
267
258
  if (!httpModule) throw TypeError(`Unsupported protocol: ${protocol}`);
268
- log({
269
- opt,
270
- protocol
271
- }, 'request');
259
+ // log({opt, protocol}, 'request')
272
260
  // Create the native request and set up its event handlers
273
261
  // @ts-ignore
274
262
  const req = httpModule.request(opt, m._onResponse);
@@ -342,11 +330,7 @@ const WriteAfterEndError = utils.createErrorType('ERR_STREAM_WRITE_AFTER_END', '
342
330
  * @returns {boolean} True if the write was successful, false otherwise.
343
331
  */ write(chunk, encoding, cb) {
344
332
  const m = this;
345
- log({
346
- data: chunk,
347
- encoding,
348
- cb
349
- }, 'write');
333
+ // log({data: chunk, encoding, cb}, 'write')
350
334
  // Writing is not allowed if end has been called
351
335
  if (m._ending) throw new WriteAfterEndError();
352
336
  // ! 数据写入时连接,pipe 时可设置 header
@@ -560,10 +544,7 @@ const WriteAfterEndError = utils.createErrorType('ERR_STREAM_WRITE_AFTER_END', '
560
544
  // even if the specific status code is not understood.
561
545
  // If the response is not a redirect; return it as-is
562
546
  const { location } = response.headers;
563
- log({
564
- statusCode,
565
- headers: response.headers
566
- }, 'processResponse');
547
+ // log({statusCode, headers: response.headers}, 'processResponse')
567
548
  if (!location || opt.followRedirects === false || statusCode < 300 || statusCode >= 400) {
568
549
  // 非重定向,返回给原始回调处理
569
550
  response.responseUrl = m._currentUrl;
@@ -674,11 +655,11 @@ const WriteAfterEndError = utils.createErrorType('ERR_STREAM_WRITE_AFTER_END', '
674
655
  ];
675
656
  // 'transfer-encoding': 'chunked'时,无content-length,axios v1.2 不能自动解压
676
657
  const responseLength = +res.headers['content-length'];
677
- log('processStream', {
678
- statusCode: res.statusCode,
679
- responseLength,
680
- headers: res.headers
681
- });
658
+ // log('processStream', {
659
+ // statusCode: res.statusCode,
660
+ // responseLength,
661
+ // headers: res.headers,
662
+ // })
682
663
  if (opt.transformStream) {
683
664
  opt.transformStream.responseLength = responseLength;
684
665
  streams.push(opt.transformStream);
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.22",
5
+ "version": "3.0.25",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "types": "types/index.d.ts",