Skip to content

Commit

Permalink
Downloader: Only write data to the sink on a 200 response
Browse files Browse the repository at this point in the history
Hopefully fixes #3278.
  • Loading branch information
edolstra committed Apr 8, 2020
1 parent 55cefd4 commit 1ab8d6a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/libstore/download.cc
Expand Up @@ -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);
})
Expand Down

0 comments on commit 1ab8d6a

Please sign in to comment.