about summary refs log tree commit diff
path: root/src/libstore/download.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-04-08T13·18+0200
committerEelco Dolstra <edolstra@gmail.com>2020-04-10T08·39+0200
commite914cfb06fd64710cb6b030b5b2c8e222745c7fb (patch)
tree9ca237fa2efabd457f77b648e15250cda3beaca1 /src/libstore/download.cc
parentd77eaf79765d685fa9a91d961858d07813cd2d20 (diff)
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>
Diffstat (limited to 'src/libstore/download.cc')
-rw-r--r--src/libstore/download.cc11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/libstore/download.cc b/src/libstore/download.cc
index b1a7a02822b6..cc78d0ba1783 100644
--- a/src/libstore/download.cc
+++ b/src/libstore/download.cc
@@ -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) {
-                    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);
               })