@wiajs/request 3.0.22 → 3.0.23
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 +12 -12
- package/dist/request.mjs +12 -12
- package/lib/request.js +11 -24
- package/package.json +1 -1
package/dist/request.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* wia request v3.0.
|
|
2
|
+
* wia request v3.0.23
|
|
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
|
|
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
|
|
557
|
+
// log('res event', {ev})
|
|
558
558
|
m.redirectReq.emit(ev, ...args); // 向上触发事件
|
|
559
559
|
};
|
|
560
560
|
|
|
@@ -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
|
|
677
|
+
// log('get property', {property})
|
|
678
678
|
return val
|
|
679
679
|
},
|
|
680
680
|
});
|
|
@@ -859,7 +859,7 @@ class Request extends stream.Duplex {
|
|
|
859
859
|
*/
|
|
860
860
|
write(chunk, encoding, cb) {
|
|
861
861
|
const m = this;
|
|
862
|
-
log
|
|
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
|
|
1123
|
+
// log({statusCode, headers: response.headers}, 'processResponse')
|
|
1124
1124
|
|
|
1125
1125
|
if (!location || opt.followRedirects === false || statusCode < 300 || statusCode >= 400) {
|
|
1126
1126
|
// 非重定向,返回给原始回调处理
|
|
@@ -1256,11 +1256,11 @@ class Request extends stream.Duplex {
|
|
|
1256
1256
|
// 'transfer-encoding': 'chunked'时,无content-length,axios v1.2 不能自动解压
|
|
1257
1257
|
const responseLength = +res.headers['content-length'];
|
|
1258
1258
|
|
|
1259
|
-
log
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
})
|
|
1259
|
+
// log('processStream', {
|
|
1260
|
+
// statusCode: res.statusCode,
|
|
1261
|
+
// responseLength,
|
|
1262
|
+
// headers: res.headers,
|
|
1263
|
+
// })
|
|
1264
1264
|
|
|
1265
1265
|
if (opt.transformStream) {
|
|
1266
1266
|
opt.transformStream.responseLength = responseLength;
|
package/dist/request.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* wia request v3.0.
|
|
2
|
+
* wia request v3.0.23
|
|
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
|
|
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
|
|
554
|
+
// log('res event', {ev})
|
|
555
555
|
m.redirectReq.emit(ev, ...args); // 向上触发事件
|
|
556
556
|
};
|
|
557
557
|
|
|
@@ -671,7 +671,7 @@ class Request extends Duplex {
|
|
|
671
671
|
get() {
|
|
672
672
|
// @ts-ignore
|
|
673
673
|
const val = m._currentRequest?.[property];
|
|
674
|
-
log
|
|
674
|
+
// log('get property', {property})
|
|
675
675
|
return val
|
|
676
676
|
},
|
|
677
677
|
});
|
|
@@ -856,7 +856,7 @@ class Request extends Duplex {
|
|
|
856
856
|
*/
|
|
857
857
|
write(chunk, encoding, cb) {
|
|
858
858
|
const m = this;
|
|
859
|
-
log
|
|
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
|
|
1120
|
+
// log({statusCode, headers: response.headers}, 'processResponse')
|
|
1121
1121
|
|
|
1122
1122
|
if (!location || opt.followRedirects === false || statusCode < 300 || statusCode >= 400) {
|
|
1123
1123
|
// 非重定向,返回给原始回调处理
|
|
@@ -1253,11 +1253,11 @@ class Request extends Duplex {
|
|
|
1253
1253
|
// 'transfer-encoding': 'chunked'时,无content-length,axios v1.2 不能自动解压
|
|
1254
1254
|
const responseLength = +res.headers['content-length'];
|
|
1255
1255
|
|
|
1256
|
-
log
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
})
|
|
1256
|
+
// log('processStream', {
|
|
1257
|
+
// statusCode: res.statusCode,
|
|
1258
|
+
// responseLength,
|
|
1259
|
+
// headers: res.headers,
|
|
1260
|
+
// })
|
|
1261
1261
|
|
|
1262
1262
|
if (opt.transformStream) {
|
|
1263
1263
|
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
|
};
|
|
@@ -193,9 +189,7 @@ const WriteAfterEndError = utils.createErrorType('ERR_STREAM_WRITE_AFTER_END', '
|
|
|
193
189
|
get () {
|
|
194
190
|
// @ts-ignore
|
|
195
191
|
const val = m._currentRequest?.[property];
|
|
196
|
-
log('get property', {
|
|
197
|
-
property
|
|
198
|
-
});
|
|
192
|
+
// log('get property', {property})
|
|
199
193
|
return val;
|
|
200
194
|
}
|
|
201
195
|
});
|
|
@@ -342,11 +336,7 @@ const WriteAfterEndError = utils.createErrorType('ERR_STREAM_WRITE_AFTER_END', '
|
|
|
342
336
|
* @returns {boolean} True if the write was successful, false otherwise.
|
|
343
337
|
*/ write(chunk, encoding, cb) {
|
|
344
338
|
const m = this;
|
|
345
|
-
log({
|
|
346
|
-
data: chunk,
|
|
347
|
-
encoding,
|
|
348
|
-
cb
|
|
349
|
-
}, 'write');
|
|
339
|
+
// log({data: chunk, encoding, cb}, 'write')
|
|
350
340
|
// Writing is not allowed if end has been called
|
|
351
341
|
if (m._ending) throw new WriteAfterEndError();
|
|
352
342
|
// ! 数据写入时连接,pipe 时可设置 header
|
|
@@ -560,10 +550,7 @@ const WriteAfterEndError = utils.createErrorType('ERR_STREAM_WRITE_AFTER_END', '
|
|
|
560
550
|
// even if the specific status code is not understood.
|
|
561
551
|
// If the response is not a redirect; return it as-is
|
|
562
552
|
const { location } = response.headers;
|
|
563
|
-
log({
|
|
564
|
-
statusCode,
|
|
565
|
-
headers: response.headers
|
|
566
|
-
}, 'processResponse');
|
|
553
|
+
// log({statusCode, headers: response.headers}, 'processResponse')
|
|
567
554
|
if (!location || opt.followRedirects === false || statusCode < 300 || statusCode >= 400) {
|
|
568
555
|
// 非重定向,返回给原始回调处理
|
|
569
556
|
response.responseUrl = m._currentUrl;
|
|
@@ -674,11 +661,11 @@ const WriteAfterEndError = utils.createErrorType('ERR_STREAM_WRITE_AFTER_END', '
|
|
|
674
661
|
];
|
|
675
662
|
// 'transfer-encoding': 'chunked'时,无content-length,axios v1.2 不能自动解压
|
|
676
663
|
const responseLength = +res.headers['content-length'];
|
|
677
|
-
log('processStream', {
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
})
|
|
664
|
+
// log('processStream', {
|
|
665
|
+
// statusCode: res.statusCode,
|
|
666
|
+
// responseLength,
|
|
667
|
+
// headers: res.headers,
|
|
668
|
+
// })
|
|
682
669
|
if (opt.transformStream) {
|
|
683
670
|
opt.transformStream.responseLength = responseLength;
|
|
684
671
|
streams.push(opt.transformStream);
|
package/package.json
CHANGED