@wiajs/request 3.0.7 → 3.0.8
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/README.md +15 -3
- package/dist/request.cjs +8 -5
- package/dist/request.mjs +8 -5
- package/lib/request.js +6 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Rebirth!
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The `request` library is undoubtedly one of the most influential libraries in Node.js. It was first released in 2011 as one of the earliest libraries in Node.js and npm, and it reached 25.7k stars on GitHub by 2019. Unfortunately, the author announced its deprecation in 2019. The reason was not due to any functional issues; in fact, its stream functionality is still among the best. Neither of its successors, Axios nor Got, comes close to request in this regard. The author believed the code was outdated and didn’t have the energy to rewrite the entire library using ES6.
|
|
4
|
+
|
|
5
|
+
`@wiajs/request` has forked `request` and rewritten the entire library using `ES6` and the latest Node.js `http`, `https`, and `stream.Duplex`. The focus was to retain its powerful stream capabilities.
|
|
6
|
+
|
|
7
|
+
How does it compare to the currently most popular library, `Axios`?
|
|
8
|
+
|
|
9
|
+
`Axios` lacks stream functionality, and the goal of rewriting request was precisely to fork `Axios` and replace Axios's transport layer to make up for this shortcoming.
|
|
10
|
+
|
|
11
|
+
- `@wiajs/request` (forked from `request`) provides powerful stream capabilities.
|
|
12
|
+
- `@wiajs/req` (forked from `axios`) provides powerful data handling capabilities.
|
|
13
|
+
- `@wiajs/request`, as the default transport for `@wiajs/req`, provides both powerful data handling and stream capabilities, as well as perfect proxy support.
|
|
14
|
+
- `@wiajs/request` is the rebirth version of request.
|
|
15
|
+
- `@wiajs/req` is a better version of axios.
|
|
4
16
|
|
|
5
17
|
For more information about why request is deprecated and possible alternatives refer to
|
|
6
18
|
[this issue](https://github.com/request/request/issues/3142).
|
|
7
19
|
|
|
8
|
-
# Request - Simplified HTTP client
|
|
20
|
+
# @wiajs/Request - Simplified HTTP client
|
|
9
21
|
|
|
10
22
|
[](https://nodei.co/npm/request/)
|
|
11
23
|
|
package/dist/request.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* wia request v3.0.
|
|
2
|
+
* wia request v3.0.8
|
|
3
3
|
* (c) 2022-2024 Sibyl Yu and contributors
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -628,7 +628,7 @@ class Request extends stream.Duplex {
|
|
|
628
628
|
// Proxy all other public ClientRequest methods
|
|
629
629
|
for (const method of ['flushHeaders', 'setNoDelay', 'setSocketKeepAlive']) {
|
|
630
630
|
m[method] = (a, b) => {
|
|
631
|
-
log$1
|
|
631
|
+
log$1(method, {a, b});
|
|
632
632
|
m._currentRequest[method](a, b);
|
|
633
633
|
};
|
|
634
634
|
}
|
|
@@ -638,13 +638,14 @@ class Request extends stream.Duplex {
|
|
|
638
638
|
Object.defineProperty(m, property, {
|
|
639
639
|
get() {
|
|
640
640
|
const val = m._currentRequest[property];
|
|
641
|
-
log$1
|
|
641
|
+
log$1('get property', {property});
|
|
642
642
|
return val
|
|
643
643
|
},
|
|
644
644
|
});
|
|
645
645
|
}
|
|
646
646
|
|
|
647
|
-
|
|
647
|
+
// 启动 startTimer
|
|
648
|
+
if (m.startTimer) m._currentRequest.once('socket', m.startTimer);
|
|
648
649
|
|
|
649
650
|
// 接收req事件,转发 到 redirectReq 发射
|
|
650
651
|
for (const ev of writeEvents) req.on(ev, writeEventEmit[ev]);
|
|
@@ -866,6 +867,8 @@ class Request extends stream.Duplex {
|
|
|
866
867
|
* @param {*} socket
|
|
867
868
|
*/
|
|
868
869
|
function startTimer(socket) {
|
|
870
|
+
if (m.startTimer) m.startTimer = null;
|
|
871
|
+
|
|
869
872
|
if (m._timeout) clearTimeout(m._timeout);
|
|
870
873
|
|
|
871
874
|
m._timeout = setTimeout(() => {
|
|
@@ -903,7 +906,7 @@ class Request extends stream.Duplex {
|
|
|
903
906
|
|
|
904
907
|
// Start the timer if or when the socket is opened
|
|
905
908
|
if (m.socket) startTimer(m.socket);
|
|
906
|
-
else m.startTimer = startTimer; //
|
|
909
|
+
else m.startTimer = startTimer; // 未连接,先登记,连接后启动
|
|
907
910
|
|
|
908
911
|
// Clean up on events
|
|
909
912
|
m.on('socket', destroyOnTimeout);
|
package/dist/request.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* wia request v3.0.
|
|
2
|
+
* wia request v3.0.8
|
|
3
3
|
* (c) 2022-2024 Sibyl Yu and contributors
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -625,7 +625,7 @@ class Request extends Duplex {
|
|
|
625
625
|
// Proxy all other public ClientRequest methods
|
|
626
626
|
for (const method of ['flushHeaders', 'setNoDelay', 'setSocketKeepAlive']) {
|
|
627
627
|
m[method] = (a, b) => {
|
|
628
|
-
log$1
|
|
628
|
+
log$1(method, {a, b});
|
|
629
629
|
m._currentRequest[method](a, b);
|
|
630
630
|
};
|
|
631
631
|
}
|
|
@@ -635,13 +635,14 @@ class Request extends Duplex {
|
|
|
635
635
|
Object.defineProperty(m, property, {
|
|
636
636
|
get() {
|
|
637
637
|
const val = m._currentRequest[property];
|
|
638
|
-
log$1
|
|
638
|
+
log$1('get property', {property});
|
|
639
639
|
return val
|
|
640
640
|
},
|
|
641
641
|
});
|
|
642
642
|
}
|
|
643
643
|
|
|
644
|
-
|
|
644
|
+
// 启动 startTimer
|
|
645
|
+
if (m.startTimer) m._currentRequest.once('socket', m.startTimer);
|
|
645
646
|
|
|
646
647
|
// 接收req事件,转发 到 redirectReq 发射
|
|
647
648
|
for (const ev of writeEvents) req.on(ev, writeEventEmit[ev]);
|
|
@@ -863,6 +864,8 @@ class Request extends Duplex {
|
|
|
863
864
|
* @param {*} socket
|
|
864
865
|
*/
|
|
865
866
|
function startTimer(socket) {
|
|
867
|
+
if (m.startTimer) m.startTimer = null;
|
|
868
|
+
|
|
866
869
|
if (m._timeout) clearTimeout(m._timeout);
|
|
867
870
|
|
|
868
871
|
m._timeout = setTimeout(() => {
|
|
@@ -900,7 +903,7 @@ class Request extends Duplex {
|
|
|
900
903
|
|
|
901
904
|
// Start the timer if or when the socket is opened
|
|
902
905
|
if (m.socket) startTimer(m.socket);
|
|
903
|
-
else m.startTimer = startTimer; //
|
|
906
|
+
else m.startTimer = startTimer; // 未连接,先登记,连接后启动
|
|
904
907
|
|
|
905
908
|
// Clean up on events
|
|
906
909
|
m.on('socket', destroyOnTimeout);
|
package/lib/request.js
CHANGED
|
@@ -199,7 +199,7 @@ const WriteAfterEndError = utils.createErrorType('ERR_STREAM_WRITE_AFTER_END', '
|
|
|
199
199
|
'setSocketKeepAlive'
|
|
200
200
|
]){
|
|
201
201
|
m[method] = (a, b)=>{
|
|
202
|
-
log
|
|
202
|
+
log(method, {
|
|
203
203
|
a,
|
|
204
204
|
b
|
|
205
205
|
});
|
|
@@ -215,14 +215,15 @@ const WriteAfterEndError = utils.createErrorType('ERR_STREAM_WRITE_AFTER_END', '
|
|
|
215
215
|
Object.defineProperty(m, property, {
|
|
216
216
|
get () {
|
|
217
217
|
const val = m._currentRequest[property];
|
|
218
|
-
log
|
|
218
|
+
log('get property', {
|
|
219
219
|
property
|
|
220
220
|
});
|
|
221
221
|
return val;
|
|
222
222
|
}
|
|
223
223
|
});
|
|
224
224
|
}
|
|
225
|
-
|
|
225
|
+
// 启动 startTimer
|
|
226
|
+
if (m.startTimer) m._currentRequest.once('socket', m.startTimer);
|
|
226
227
|
// 接收req事件,转发 到 redirectReq 发射
|
|
227
228
|
for (const ev of writeEvents)req.on(ev, writeEventEmit[ev]);
|
|
228
229
|
// RFC7230§5.3.1: When making a request directly to an origin server, […]
|
|
@@ -402,6 +403,7 @@ const WriteAfterEndError = utils.createErrorType('ERR_STREAM_WRITE_AFTER_END', '
|
|
|
402
403
|
* Sets up a timer to trigger a timeout event
|
|
403
404
|
* @param {*} socket
|
|
404
405
|
*/ function startTimer(socket) {
|
|
406
|
+
if (m.startTimer) m.startTimer = null;
|
|
405
407
|
if (m._timeout) clearTimeout(m._timeout);
|
|
406
408
|
m._timeout = setTimeout(()=>{
|
|
407
409
|
m.emit('timeout');
|
|
@@ -432,7 +434,7 @@ const WriteAfterEndError = utils.createErrorType('ERR_STREAM_WRITE_AFTER_END', '
|
|
|
432
434
|
if (callback) m.on('timeout', callback);
|
|
433
435
|
// Start the timer if or when the socket is opened
|
|
434
436
|
if (m.socket) startTimer(m.socket);
|
|
435
|
-
else m.startTimer = startTimer //
|
|
437
|
+
else m.startTimer = startTimer // 未连接,先登记,连接后启动
|
|
436
438
|
;
|
|
437
439
|
// Clean up on events
|
|
438
440
|
m.on('socket', destroyOnTimeout);
|