Downloader: Only write data to the sink on a 200 response

Hopefully fixes #3278.

(cherry picked from commit 1ab8d6ac1861e9405ae34af3deb681020c03e82d)
Signed-off-by: Domen Kožar <domen@dev.si>
This commit is contained in:
Eelco Dolstra 2020-04-08 15:18:41 +02:00
parent d77eaf7976
commit e914cfb06f

View file

@ -86,8 +86,15 @@ struct CurlDownloader : public Downloader
, callback(std::move(callback))
, finalSink([this](const unsigned char * data, size_t len) {
if (this->request.dataCallback) {
long httpStatus = 0;
curl_easy_getinfo(req, CURLINFO_RESPONSE_CODE, &httpStatus);
/* Only write data to the sink if this is a
successful response. */
if (httpStatus == 0 || httpStatus == 200 || httpStatus == 201 || httpStatus == 206) {
writtenToSink += len;
this->request.dataCallback((char *) data, len);
}
} else
this->result.data->append((char *) data, len);
})