mirror of
https://github.com/tenrok/axios.git
synced 2026-05-15 11:59:42 +03:00
fix(fetch): fix & optimize progress capturing for cases when the request data has a nullish value or zero data length (#6400)
This commit is contained in:
+16
-7
@@ -59,6 +59,10 @@ isFetchSupported && (((res) => {
|
||||
})(new Response));
|
||||
|
||||
const getBodyLength = async (body) => {
|
||||
if (body == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(utils.isBlob(body)) {
|
||||
return body.size;
|
||||
}
|
||||
@@ -117,10 +121,13 @@ export default isFetchSupported && (async (config) => {
|
||||
finished = true;
|
||||
}
|
||||
|
||||
try {
|
||||
if (onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head') {
|
||||
let requestContentLength = await resolveBodyLength(headers, data);
|
||||
let requestContentLength;
|
||||
|
||||
try {
|
||||
if (
|
||||
onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
|
||||
(requestContentLength = await resolveBodyLength(headers, data)) !== 0
|
||||
) {
|
||||
let _request = new Request(url, {
|
||||
method: 'POST',
|
||||
body: data,
|
||||
@@ -133,10 +140,12 @@ export default isFetchSupported && (async (config) => {
|
||||
headers.setContentType(contentTypeHeader)
|
||||
}
|
||||
|
||||
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, fetchProgressDecorator(
|
||||
requestContentLength,
|
||||
progressEventReducer(onUploadProgress)
|
||||
));
|
||||
if (_request.body) {
|
||||
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, fetchProgressDecorator(
|
||||
requestContentLength,
|
||||
progressEventReducer(onUploadProgress)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if (!utils.isString(withCredentials)) {
|
||||
|
||||
Reference in New Issue
Block a user