From f95c320500548c9262b3d77898509fbb36c346b4 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Fri, 22 Jan 2021 14:46:40 -0600 Subject: [PATCH] Handle missing etag in 304 Not Modified response GitHub now omits the etag, but 304 implies it matches the one we provided. Just use that one to avoid having an etag-less resource. Fixes #4469 (cherry picked from commit a76682466062ef2c972d19f259feeef1c46a44a3) --- src/libstore/download.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libstore/download.cc b/src/libstore/download.cc index 80674a9e7..b439ddf0c 100644 --- a/src/libstore/download.cc +++ b/src/libstore/download.cc @@ -349,6 +349,13 @@ struct CurlDownloader : public Downloader (httpStatus == 200 || httpStatus == 201 || httpStatus == 204 || httpStatus == 206 || httpStatus == 304 || httpStatus == 226 /* FTP */ || httpStatus == 0 /* other protocol */)) { result.cached = httpStatus == 304; + + // In 2021, GitHub responds to If-None-Match with 304, + // but omits ETag. We just use the If-None-Match etag + // since 304 implies they are the same. + if (httpStatus == 304 && result.etag == "") + result.etag = request.expectedETag; + act.progress(result.bodySize, result.bodySize); done = true; callback(std::move(result));