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:
Tamás Bálint Misius 2023-05-27 20:16:16 +02:00
parent 16e1ca74f2
commit f23a3dd2f8
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
3 changed files with 12 additions and 5 deletions

View File

@ -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;
}
}

View File

@ -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;

View File

@ -42,7 +42,14 @@ private:
{
int total, done;
std::tie(total, done) = request->CheckProgress();
if (total == -1)
{
notifyProgress(-1);
}
else
{
notifyProgress(total ? done * 100 / total : 0);
}
Platform::Millisleep(1);
}