diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-04-08 17:15:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-08 17:15:53 +0200 |
commit | 96f3c36709a8f246ecb9faf9e8b82706552f3856 (patch) | |
tree | 31ef4f81f483a11b2b7e7060d9c2333304bd9192 /src | |
parent | 9ed097db7bc052964e87506527b49715e2ce9ff6 (diff) | |
parent | 1ab8d6ac1861e9405ae34af3deb681020c03e82d (diff) |
Merge pull request #3478 from edolstra/ignore-failed-data
Downloader: Only write data to the sink on a 200 response
Diffstat (limited to 'src')
-rw-r--r-- | src/libstore/download.cc | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/libstore/download.cc b/src/libstore/download.cc index af69699a8..bc875f653 100644 --- a/src/libstore/download.cc +++ b/src/libstore/download.cc @@ -83,8 +83,15 @@ struct CurlDownloader : public Downloader , callback(std::move(callback)) , finalSink([this](const unsigned char * data, size_t len) { if (this->request.dataCallback) { - writtenToSink += len; - this->request.dataCallback((char *) data, len); + 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); }) |