@wiajs/request 3.0.26 → 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 +23 -1
- package/dist/request.mjs +23 -1
- package/lib/index.js +24 -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
|
*/
|
|
@@ -1709,6 +1709,28 @@ function fn(verb) {
|
|
|
1709
1709
|
const {opts, cb} = init(uri, options, callback);
|
|
1710
1710
|
opts.method = method;
|
|
1711
1711
|
const req = new Request(opts, cb);
|
|
1712
|
+
const {data, stream} = opts;
|
|
1713
|
+
// 非流模式,自动发送请求,流模式通过流写入发送
|
|
1714
|
+
if (!stream) {
|
|
1715
|
+
// 发送数据
|
|
1716
|
+
if (utils.isStream(data)) {
|
|
1717
|
+
|
|
1718
|
+
data.on('end', () => {
|
|
1719
|
+
});
|
|
1720
|
+
|
|
1721
|
+
data.once(
|
|
1722
|
+
'error',
|
|
1723
|
+
/** @param {*} err */ err => {
|
|
1724
|
+
// req.destroy(err)
|
|
1725
|
+
}
|
|
1726
|
+
);
|
|
1727
|
+
|
|
1728
|
+
data.on('close', () => {
|
|
1729
|
+
});
|
|
1730
|
+
|
|
1731
|
+
data.pipe(req); // 写入数据流
|
|
1732
|
+
} else req.end(data);
|
|
1733
|
+
}
|
|
1712
1734
|
return req
|
|
1713
1735
|
}
|
|
1714
1736
|
}
|
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
|
*/
|
|
@@ -1706,6 +1706,28 @@ function fn(verb) {
|
|
|
1706
1706
|
const {opts, cb} = init(uri, options, callback);
|
|
1707
1707
|
opts.method = method;
|
|
1708
1708
|
const req = new Request(opts, cb);
|
|
1709
|
+
const {data, stream} = opts;
|
|
1710
|
+
// 非流模式,自动发送请求,流模式通过流写入发送
|
|
1711
|
+
if (!stream) {
|
|
1712
|
+
// 发送数据
|
|
1713
|
+
if (utils.isStream(data)) {
|
|
1714
|
+
|
|
1715
|
+
data.on('end', () => {
|
|
1716
|
+
});
|
|
1717
|
+
|
|
1718
|
+
data.once(
|
|
1719
|
+
'error',
|
|
1720
|
+
/** @param {*} err */ err => {
|
|
1721
|
+
// req.destroy(err)
|
|
1722
|
+
}
|
|
1723
|
+
);
|
|
1724
|
+
|
|
1725
|
+
data.on('close', () => {
|
|
1726
|
+
});
|
|
1727
|
+
|
|
1728
|
+
data.pipe(req); // 写入数据流
|
|
1729
|
+
} else req.end(data);
|
|
1730
|
+
}
|
|
1709
1731
|
return req
|
|
1710
1732
|
}
|
|
1711
1733
|
}
|
package/lib/index.js
CHANGED
|
@@ -121,6 +121,30 @@ const WritebBeenAbortedError = utils.createErrorType('ERR_STREAM_WRITE_BEEN_ABOR
|
|
|
121
121
|
const { opts, cb } = init(uri, options, callback);
|
|
122
122
|
opts.method = method;
|
|
123
123
|
const req = new Request(opts, cb);
|
|
124
|
+
const { data, stream } = opts;
|
|
125
|
+
// 非流模式,自动发送请求,流模式通过流写入发送
|
|
126
|
+
if (!stream) {
|
|
127
|
+
// 发送数据
|
|
128
|
+
if (utils.isStream(data)) {
|
|
129
|
+
// Send the request
|
|
130
|
+
let ended = false;
|
|
131
|
+
let errored = false;
|
|
132
|
+
data.on('end', ()=>{
|
|
133
|
+
ended = true;
|
|
134
|
+
});
|
|
135
|
+
data.once('error', /** @param {*} err */ (err)=>{
|
|
136
|
+
errored = true;
|
|
137
|
+
// req.destroy(err)
|
|
138
|
+
});
|
|
139
|
+
data.on('close', ()=>{
|
|
140
|
+
if (!ended && !errored) {
|
|
141
|
+
// throw new WritebBeenAbortedError()
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
data.pipe(req) // 写入数据流
|
|
145
|
+
;
|
|
146
|
+
} else req.end(data);
|
|
147
|
+
}
|
|
124
148
|
return req;
|
|
125
149
|
};
|
|
126
150
|
}
|
package/package.json
CHANGED