Fix unknown HTTP response body size being reported as 0 in some cases
Namely, when libcurl dies or when progress is checked before the request is started, although this should never happen.
This commit is contained in:
parent
16e1ca74f2
commit
f23a3dd2f8
@ -371,11 +371,11 @@ namespace http
|
||||
{
|
||||
#ifdef REQUEST_USE_CURL_OFFSET_T
|
||||
curl_off_t total, done;
|
||||
HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &total));
|
||||
HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &total)); // stores -1 if unknown
|
||||
HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_SIZE_DOWNLOAD_T, &done));
|
||||
#else
|
||||
double total, done;
|
||||
HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &total));
|
||||
HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &total)); // stores -1 if unknown
|
||||
HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_SIZE_DOWNLOAD, &done));
|
||||
#endif
|
||||
handle->bytesTotal = int(total);
|
||||
@ -383,7 +383,7 @@ namespace http
|
||||
}
|
||||
else
|
||||
{
|
||||
handle->bytesTotal = 0;
|
||||
handle->bytesTotal = -1;
|
||||
handle->bytesDone = 0;
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ namespace http
|
||||
State state = ready;
|
||||
std::mutex stateMx;
|
||||
std::condition_variable stateCv;
|
||||
std::atomic<int> bytesTotal = 0;
|
||||
std::atomic<int> bytesTotal = -1;
|
||||
std::atomic<int> bytesDone = 0;
|
||||
int statusCode = 0;
|
||||
ByteString responseData;
|
||||
|
@ -42,7 +42,14 @@ private:
|
||||
{
|
||||
int total, done;
|
||||
std::tie(total, done) = request->CheckProgress();
|
||||
notifyProgress(total ? done * 100 / total : 0);
|
||||
if (total == -1)
|
||||
{
|
||||
notifyProgress(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
notifyProgress(total ? done * 100 / total : 0);
|
||||
}
|
||||
Platform::Millisleep(1);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user