@wiajs/request 3.0.25 → 3.0.27
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 +67 -12
- package/dist/request.mjs +67 -12
- package/lib/index.js +29 -3
- package/lib/request.js +27 -0
- 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.27
|
|
3
3
|
* (c) 2022-2024 Sibyl Yu and contributors
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -469,6 +469,7 @@ const log$1 = log$2.log({env: `wia:req:${log$2.name((typeof document === 'undefi
|
|
|
469
469
|
* @prop {number} [maxRedirects=21]
|
|
470
470
|
* @prop {number} [maxBodyLength = 0]
|
|
471
471
|
* @prop {*} [trackRedirects]
|
|
472
|
+
* @prop {*} [data]
|
|
472
473
|
*/
|
|
473
474
|
|
|
474
475
|
/** @typedef {object} ResponseExt
|
|
@@ -848,6 +849,35 @@ class Request extends stream.Duplex {
|
|
|
848
849
|
return this
|
|
849
850
|
}
|
|
850
851
|
|
|
852
|
+
/**
|
|
853
|
+
* 发送数据
|
|
854
|
+
*/
|
|
855
|
+
send() {
|
|
856
|
+
const m = this;
|
|
857
|
+
const {data} = m.opt;
|
|
858
|
+
// 发送数据
|
|
859
|
+
if (utils.isStream(data)) {
|
|
860
|
+
|
|
861
|
+
data.on('end', () => {
|
|
862
|
+
});
|
|
863
|
+
|
|
864
|
+
data.once(
|
|
865
|
+
'error',
|
|
866
|
+
/** @param {*} err */ err => {
|
|
867
|
+
// req.destroy(err)
|
|
868
|
+
}
|
|
869
|
+
);
|
|
870
|
+
|
|
871
|
+
data.on('close', () => {
|
|
872
|
+
// if (!ended && !errored) {
|
|
873
|
+
// throw new WritebBeenAbortedError()
|
|
874
|
+
// }
|
|
875
|
+
});
|
|
876
|
+
|
|
877
|
+
data.pipe(m); // 写入数据流
|
|
878
|
+
} else m.end(data);
|
|
879
|
+
}
|
|
880
|
+
|
|
851
881
|
/**
|
|
852
882
|
* Writes buffered data to the current native request
|
|
853
883
|
* 如 request 不存在,则创建连接,pipe 时可写入 header
|
|
@@ -1542,7 +1572,7 @@ function isSubdomain(subdomain, domain) {
|
|
|
1542
1572
|
|
|
1543
1573
|
const log = log$2.log({env: `wia:req:${log$2.name((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('request.cjs', document.baseURI).href)))}`}); // __filename
|
|
1544
1574
|
|
|
1545
|
-
|
|
1575
|
+
utils.createErrorType(
|
|
1546
1576
|
'ERR_STREAM_WRITE_BEEN_ABORTED',
|
|
1547
1577
|
'Request stream has been aborted'
|
|
1548
1578
|
)
|
|
@@ -1623,7 +1653,39 @@ function request(uri, options, callback) {
|
|
|
1623
1653
|
try {
|
|
1624
1654
|
const {opts, cb} = init(uri, options, callback);
|
|
1625
1655
|
// log({uri, options, opts}, 'request')
|
|
1626
|
-
|
|
1656
|
+
const req = new Request(opts, cb);
|
|
1657
|
+
const {data, stream} = opts;
|
|
1658
|
+
// 非流模式,自动发送请求,流模式通过流写入发送
|
|
1659
|
+
if (!stream) {
|
|
1660
|
+
// 发送数据
|
|
1661
|
+
if (utils.isStream(data)) {
|
|
1662
|
+
// Send the request
|
|
1663
|
+
let ended = false;
|
|
1664
|
+
let errored = false;
|
|
1665
|
+
|
|
1666
|
+
data.on('end', () => {
|
|
1667
|
+
ended = true;
|
|
1668
|
+
});
|
|
1669
|
+
|
|
1670
|
+
data.once(
|
|
1671
|
+
'error',
|
|
1672
|
+
/** @param {*} err */ err => {
|
|
1673
|
+
errored = true;
|
|
1674
|
+
// req.destroy(err)
|
|
1675
|
+
}
|
|
1676
|
+
);
|
|
1677
|
+
|
|
1678
|
+
data.on('close', () => {
|
|
1679
|
+
if (!ended && !errored) {
|
|
1680
|
+
// throw new WritebBeenAbortedError()
|
|
1681
|
+
}
|
|
1682
|
+
});
|
|
1683
|
+
|
|
1684
|
+
data.pipe(req); // 写入数据流
|
|
1685
|
+
} else req.end(data);
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
R = req;
|
|
1627
1689
|
} catch (e) {
|
|
1628
1690
|
log.err(e, 'request');
|
|
1629
1691
|
}
|
|
@@ -1648,29 +1710,22 @@ function fn(verb) {
|
|
|
1648
1710
|
opts.method = method;
|
|
1649
1711
|
const req = new Request(opts, cb);
|
|
1650
1712
|
const {data, stream} = opts;
|
|
1713
|
+
// 非流模式,自动发送请求,流模式通过流写入发送
|
|
1651
1714
|
if (!stream) {
|
|
1652
1715
|
// 发送数据
|
|
1653
1716
|
if (utils.isStream(data)) {
|
|
1654
|
-
// Send the request
|
|
1655
|
-
let ended = false;
|
|
1656
|
-
let errored = false;
|
|
1657
1717
|
|
|
1658
1718
|
data.on('end', () => {
|
|
1659
|
-
ended = true;
|
|
1660
1719
|
});
|
|
1661
1720
|
|
|
1662
1721
|
data.once(
|
|
1663
1722
|
'error',
|
|
1664
1723
|
/** @param {*} err */ err => {
|
|
1665
|
-
|
|
1666
|
-
req.destroy(err);
|
|
1724
|
+
// req.destroy(err)
|
|
1667
1725
|
}
|
|
1668
1726
|
);
|
|
1669
1727
|
|
|
1670
1728
|
data.on('close', () => {
|
|
1671
|
-
if (!ended && !errored) {
|
|
1672
|
-
throw new WritebBeenAbortedError()
|
|
1673
|
-
}
|
|
1674
1729
|
});
|
|
1675
1730
|
|
|
1676
1731
|
data.pipe(req); // 写入数据流
|
package/dist/request.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* wia request v3.0.
|
|
2
|
+
* wia request v3.0.27
|
|
3
3
|
* (c) 2022-2024 Sibyl Yu and contributors
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -466,6 +466,7 @@ const log$1 = log$2({env: `wia:req:${name(import.meta.url)}`}); // __filename
|
|
|
466
466
|
* @prop {number} [maxRedirects=21]
|
|
467
467
|
* @prop {number} [maxBodyLength = 0]
|
|
468
468
|
* @prop {*} [trackRedirects]
|
|
469
|
+
* @prop {*} [data]
|
|
469
470
|
*/
|
|
470
471
|
|
|
471
472
|
/** @typedef {object} ResponseExt
|
|
@@ -845,6 +846,35 @@ class Request extends Duplex {
|
|
|
845
846
|
return this
|
|
846
847
|
}
|
|
847
848
|
|
|
849
|
+
/**
|
|
850
|
+
* 发送数据
|
|
851
|
+
*/
|
|
852
|
+
send() {
|
|
853
|
+
const m = this;
|
|
854
|
+
const {data} = m.opt;
|
|
855
|
+
// 发送数据
|
|
856
|
+
if (utils.isStream(data)) {
|
|
857
|
+
|
|
858
|
+
data.on('end', () => {
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
data.once(
|
|
862
|
+
'error',
|
|
863
|
+
/** @param {*} err */ err => {
|
|
864
|
+
// req.destroy(err)
|
|
865
|
+
}
|
|
866
|
+
);
|
|
867
|
+
|
|
868
|
+
data.on('close', () => {
|
|
869
|
+
// if (!ended && !errored) {
|
|
870
|
+
// throw new WritebBeenAbortedError()
|
|
871
|
+
// }
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
data.pipe(m); // 写入数据流
|
|
875
|
+
} else m.end(data);
|
|
876
|
+
}
|
|
877
|
+
|
|
848
878
|
/**
|
|
849
879
|
* Writes buffered data to the current native request
|
|
850
880
|
* 如 request 不存在,则创建连接,pipe 时可写入 header
|
|
@@ -1539,7 +1569,7 @@ function isSubdomain(subdomain, domain) {
|
|
|
1539
1569
|
|
|
1540
1570
|
const log = log$2({env: `wia:req:${name(import.meta.url)}`}); // __filename
|
|
1541
1571
|
|
|
1542
|
-
|
|
1572
|
+
utils.createErrorType(
|
|
1543
1573
|
'ERR_STREAM_WRITE_BEEN_ABORTED',
|
|
1544
1574
|
'Request stream has been aborted'
|
|
1545
1575
|
)
|
|
@@ -1620,7 +1650,39 @@ function request(uri, options, callback) {
|
|
|
1620
1650
|
try {
|
|
1621
1651
|
const {opts, cb} = init(uri, options, callback);
|
|
1622
1652
|
// log({uri, options, opts}, 'request')
|
|
1623
|
-
|
|
1653
|
+
const req = new Request(opts, cb);
|
|
1654
|
+
const {data, stream} = opts;
|
|
1655
|
+
// 非流模式,自动发送请求,流模式通过流写入发送
|
|
1656
|
+
if (!stream) {
|
|
1657
|
+
// 发送数据
|
|
1658
|
+
if (utils.isStream(data)) {
|
|
1659
|
+
// Send the request
|
|
1660
|
+
let ended = false;
|
|
1661
|
+
let errored = false;
|
|
1662
|
+
|
|
1663
|
+
data.on('end', () => {
|
|
1664
|
+
ended = true;
|
|
1665
|
+
});
|
|
1666
|
+
|
|
1667
|
+
data.once(
|
|
1668
|
+
'error',
|
|
1669
|
+
/** @param {*} err */ err => {
|
|
1670
|
+
errored = true;
|
|
1671
|
+
// req.destroy(err)
|
|
1672
|
+
}
|
|
1673
|
+
);
|
|
1674
|
+
|
|
1675
|
+
data.on('close', () => {
|
|
1676
|
+
if (!ended && !errored) {
|
|
1677
|
+
// throw new WritebBeenAbortedError()
|
|
1678
|
+
}
|
|
1679
|
+
});
|
|
1680
|
+
|
|
1681
|
+
data.pipe(req); // 写入数据流
|
|
1682
|
+
} else req.end(data);
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
R = req;
|
|
1624
1686
|
} catch (e) {
|
|
1625
1687
|
log.err(e, 'request');
|
|
1626
1688
|
}
|
|
@@ -1645,29 +1707,22 @@ function fn(verb) {
|
|
|
1645
1707
|
opts.method = method;
|
|
1646
1708
|
const req = new Request(opts, cb);
|
|
1647
1709
|
const {data, stream} = opts;
|
|
1710
|
+
// 非流模式,自动发送请求,流模式通过流写入发送
|
|
1648
1711
|
if (!stream) {
|
|
1649
1712
|
// 发送数据
|
|
1650
1713
|
if (utils.isStream(data)) {
|
|
1651
|
-
// Send the request
|
|
1652
|
-
let ended = false;
|
|
1653
|
-
let errored = false;
|
|
1654
1714
|
|
|
1655
1715
|
data.on('end', () => {
|
|
1656
|
-
ended = true;
|
|
1657
1716
|
});
|
|
1658
1717
|
|
|
1659
1718
|
data.once(
|
|
1660
1719
|
'error',
|
|
1661
1720
|
/** @param {*} err */ err => {
|
|
1662
|
-
|
|
1663
|
-
req.destroy(err);
|
|
1721
|
+
// req.destroy(err)
|
|
1664
1722
|
}
|
|
1665
1723
|
);
|
|
1666
1724
|
|
|
1667
1725
|
data.on('close', () => {
|
|
1668
|
-
if (!ended && !errored) {
|
|
1669
|
-
throw new WritebBeenAbortedError()
|
|
1670
|
-
}
|
|
1671
1726
|
});
|
|
1672
1727
|
|
|
1673
1728
|
data.pipe(req); // 写入数据流
|
package/lib/index.js
CHANGED
|
@@ -76,7 +76,32 @@ const WritebBeenAbortedError = utils.createErrorType('ERR_STREAM_WRITE_BEEN_ABOR
|
|
|
76
76
|
try {
|
|
77
77
|
const { opts, cb } = init(uri, options, callback);
|
|
78
78
|
// log({uri, options, opts}, 'request')
|
|
79
|
-
|
|
79
|
+
const req = new Request(opts, cb);
|
|
80
|
+
const { data, stream } = opts;
|
|
81
|
+
// 非流模式,自动发送请求,流模式通过流写入发送
|
|
82
|
+
if (!stream) {
|
|
83
|
+
// 发送数据
|
|
84
|
+
if (utils.isStream(data)) {
|
|
85
|
+
// Send the request
|
|
86
|
+
let ended = false;
|
|
87
|
+
let errored = false;
|
|
88
|
+
data.on('end', ()=>{
|
|
89
|
+
ended = true;
|
|
90
|
+
});
|
|
91
|
+
data.once('error', /** @param {*} err */ (err)=>{
|
|
92
|
+
errored = true;
|
|
93
|
+
// req.destroy(err)
|
|
94
|
+
});
|
|
95
|
+
data.on('close', ()=>{
|
|
96
|
+
if (!ended && !errored) {
|
|
97
|
+
// throw new WritebBeenAbortedError()
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
data.pipe(req) // 写入数据流
|
|
101
|
+
;
|
|
102
|
+
} else req.end(data);
|
|
103
|
+
}
|
|
104
|
+
R = req;
|
|
80
105
|
} catch (e) {
|
|
81
106
|
log.err(e, 'request');
|
|
82
107
|
}
|
|
@@ -97,6 +122,7 @@ const WritebBeenAbortedError = utils.createErrorType('ERR_STREAM_WRITE_BEEN_ABOR
|
|
|
97
122
|
opts.method = method;
|
|
98
123
|
const req = new Request(opts, cb);
|
|
99
124
|
const { data, stream } = opts;
|
|
125
|
+
// 非流模式,自动发送请求,流模式通过流写入发送
|
|
100
126
|
if (!stream) {
|
|
101
127
|
// 发送数据
|
|
102
128
|
if (utils.isStream(data)) {
|
|
@@ -108,11 +134,11 @@ const WritebBeenAbortedError = utils.createErrorType('ERR_STREAM_WRITE_BEEN_ABOR
|
|
|
108
134
|
});
|
|
109
135
|
data.once('error', /** @param {*} err */ (err)=>{
|
|
110
136
|
errored = true;
|
|
111
|
-
|
|
137
|
+
// req.destroy(err)
|
|
112
138
|
});
|
|
113
139
|
data.on('close', ()=>{
|
|
114
140
|
if (!ended && !errored) {
|
|
115
|
-
|
|
141
|
+
// throw new WritebBeenAbortedError()
|
|
116
142
|
}
|
|
117
143
|
});
|
|
118
144
|
data.pipe(req) // 写入数据流
|
package/lib/request.js
CHANGED
|
@@ -35,6 +35,7 @@ const log = Log({
|
|
|
35
35
|
* @prop {number} [maxRedirects=21]
|
|
36
36
|
* @prop {number} [maxBodyLength = 0]
|
|
37
37
|
* @prop {*} [trackRedirects]
|
|
38
|
+
* @prop {*} [data]
|
|
38
39
|
*/ /** @typedef {object} ResponseExt
|
|
39
40
|
* @prop {*[]} [redirects]
|
|
40
41
|
* @prop {string} [responseUrl]
|
|
@@ -321,6 +322,32 @@ const WriteAfterEndError = utils.createErrorType('ERR_STREAM_WRITE_AFTER_END', '
|
|
|
321
322
|
return this;
|
|
322
323
|
}
|
|
323
324
|
/**
|
|
325
|
+
* 发送数据
|
|
326
|
+
*/ send() {
|
|
327
|
+
const m = this;
|
|
328
|
+
const { data } = m.opt;
|
|
329
|
+
// 发送数据
|
|
330
|
+
if (utils.isStream(data)) {
|
|
331
|
+
// Send the request
|
|
332
|
+
let ended = false;
|
|
333
|
+
let errored = false;
|
|
334
|
+
data.on('end', ()=>{
|
|
335
|
+
ended = true;
|
|
336
|
+
});
|
|
337
|
+
data.once('error', /** @param {*} err */ (err)=>{
|
|
338
|
+
errored = true;
|
|
339
|
+
// req.destroy(err)
|
|
340
|
+
});
|
|
341
|
+
data.on('close', ()=>{
|
|
342
|
+
// if (!ended && !errored) {
|
|
343
|
+
// throw new WritebBeenAbortedError()
|
|
344
|
+
// }
|
|
345
|
+
});
|
|
346
|
+
data.pipe(m) // 写入数据流
|
|
347
|
+
;
|
|
348
|
+
} else m.end(data);
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
324
351
|
* Writes buffered data to the current native request
|
|
325
352
|
* 如 request 不存在,则创建连接,pipe 时可写入 header
|
|
326
353
|
* @override - 重写父类方法
|
package/package.json
CHANGED