mirror of
https://github.com/tenrok/axios.git
synced 2026-06-14 18:42:33 +03:00
Fixed Z_BUF_ERROR when content-encoding is set but the response body is empty; (#5250)
Fixed download progress capturing for compressed responses; Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
+18
-18
@@ -373,6 +373,23 @@ export default function httpAdapter(config) {
|
||||
|
||||
const streams = [res];
|
||||
|
||||
const responseLength = +res.headers['content-length'];
|
||||
|
||||
if (onDownloadProgress) {
|
||||
const transformStream = new AxiosTransformStream({
|
||||
length: utils.toFiniteNumber(responseLength),
|
||||
maxRate: utils.toFiniteNumber(maxDownloadRate)
|
||||
});
|
||||
|
||||
onDownloadProgress && transformStream.on('progress', progress => {
|
||||
onDownloadProgress(Object.assign(progress, {
|
||||
download: true
|
||||
}));
|
||||
});
|
||||
|
||||
streams.push(transformStream);
|
||||
}
|
||||
|
||||
// uncompress the response body transparently if required
|
||||
let responseStream = res;
|
||||
|
||||
@@ -383,7 +400,7 @@ export default function httpAdapter(config) {
|
||||
if (config.decompress !== false) {
|
||||
// if no content, but headers still say that it is encoded,
|
||||
// remove the header not confuse downstream operations
|
||||
if (data && data.length === 0 && res.headers['content-encoding']) {
|
||||
if ((!responseLength || res.statusCode === 204) && res.headers['content-encoding']) {
|
||||
delete res.headers['content-encoding'];
|
||||
}
|
||||
|
||||
@@ -406,23 +423,6 @@ export default function httpAdapter(config) {
|
||||
}
|
||||
}
|
||||
|
||||
if (onDownloadProgress) {
|
||||
const responseLength = +res.headers['content-length'];
|
||||
|
||||
const transformStream = new AxiosTransformStream({
|
||||
length: utils.toFiniteNumber(responseLength),
|
||||
maxRate: utils.toFiniteNumber(maxDownloadRate)
|
||||
});
|
||||
|
||||
onDownloadProgress && transformStream.on('progress', progress => {
|
||||
onDownloadProgress(Object.assign(progress, {
|
||||
download: true
|
||||
}));
|
||||
});
|
||||
|
||||
streams.push(transformStream);
|
||||
}
|
||||
|
||||
responseStream = streams.length > 1 ? stream.pipeline(streams, utils.noop) : streams[0];
|
||||
|
||||
const offListeners = stream.finished(responseStream, () => {
|
||||
|
||||
Reference in New Issue
Block a user