Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/libstore/filetransfer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
#include "nix/util/callback.hh"
#include "nix/util/signals.hh"

#include "nix/util/util.hh"
#include "store-config-private.hh"
#include "nix/store/s3-url.hh"
#include <optional>
#include <string_view>
#if NIX_WITH_AWS_AUTH
# include "nix/store/aws-creds.hh"
#endif
Expand Down Expand Up @@ -177,7 +179,7 @@ struct curlFileTransfer : public FileTransfer
#if NIX_WITH_AWS_AUTH
if (!request.awsSigV4Provider)
#endif
appendHeaders("Accept-Encoding: zstd, br, gzip, deflate, bzip2, xz");
appendHeaders("Accept-Encoding: zstd, br, gzip, deflate, bzip2");
if (!request.expectedETag.empty())
appendHeaders("If-None-Match: " + request.expectedETag);
if (!request.mimeType.empty())
Expand Down Expand Up @@ -275,6 +277,29 @@ struct curlFileTransfer : public FileTransfer
result.urls.push_back(effectiveUriCStr);
}

static std::string parseContentEncoding(std::string_view contentEncoding)
{

if (contentEncoding.find(",") != std::string::npos) {
throw nix::Error("Stacked Content-Encoding is not supported: %s", contentEncoding);
}

if (contentEncoding == "gzip" || contentEncoding == "x-gzip")
return "gzip";
else if (contentEncoding == "compress" || contentEncoding == "x-compress")
return "compress";
else if (contentEncoding == "br")
return "br";
else if (contentEncoding == "zstd")
return "zstd";
else if (contentEncoding == "bzip2")
return "bzip2";
else if (contentEncoding == "identity")
return "identity";

throw nix::Error("Invalid content-encoding: %s", contentEncoding);
}

size_t headerCallback(void * contents, size_t size, size_t nmemb) noexcept
try {
size_t realSize = size * nmemb;
Expand Down Expand Up @@ -311,8 +336,11 @@ struct curlFileTransfer : public FileTransfer
}
}

/* https://www.rfc-editor.org/rfc/rfc9110.html#name-content-codings
* All content codings are case-insensitive and ought to be
* registered within the "HTTP Content Coding Registry" */
else if (name == "content-encoding")
encoding = trim(line.substr(i + 1));
encoding = parseContentEncoding(toLower(trim(line.substr(i + 1))));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a comment referring to the spec paragraph about case insensitivity?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this.


else if (name == "accept-ranges" && toLower(trim(line.substr(i + 1))) == "bytes")
acceptRanges = true;
Expand Down