mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 12:06:01 +01:00
Merge pull request #14335 from lovesegfault/extract-getcompressionmethod
refactor(libstore): extract getCompressionMethod() in HttpBinaryCacheStore
This commit is contained in:
commit
5d7912eb18
1 changed files with 15 additions and 13 deletions
|
|
@ -97,6 +97,18 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
std::optional<std::string> getCompressionMethod(const std::string & path)
|
||||||
|
{
|
||||||
|
if (hasSuffix(path, ".narinfo") && !config->narinfoCompression.get().empty())
|
||||||
|
return config->narinfoCompression;
|
||||||
|
else if (hasSuffix(path, ".ls") && !config->lsCompression.get().empty())
|
||||||
|
return config->lsCompression;
|
||||||
|
else if (hasPrefix(path, "log/") && !config->logCompression.get().empty())
|
||||||
|
return config->logCompression;
|
||||||
|
else
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
void maybeDisable()
|
void maybeDisable()
|
||||||
{
|
{
|
||||||
auto state(_state.lock());
|
auto state(_state.lock());
|
||||||
|
|
@ -149,19 +161,9 @@ protected:
|
||||||
|
|
||||||
auto data = StreamToSourceAdapter(istream).drain();
|
auto data = StreamToSourceAdapter(istream).drain();
|
||||||
|
|
||||||
// Determine compression method based on file type
|
if (auto compressionMethod = getCompressionMethod(path)) {
|
||||||
std::string compressionMethod;
|
data = compress(*compressionMethod, data);
|
||||||
if (hasSuffix(path, ".narinfo"))
|
req.headers.emplace_back("Content-Encoding", *compressionMethod);
|
||||||
compressionMethod = config->narinfoCompression;
|
|
||||||
else if (hasSuffix(path, ".ls"))
|
|
||||||
compressionMethod = config->lsCompression;
|
|
||||||
else if (hasPrefix(path, "log/"))
|
|
||||||
compressionMethod = config->logCompression;
|
|
||||||
|
|
||||||
// Apply compression if configured
|
|
||||||
if (!compressionMethod.empty()) {
|
|
||||||
data = compress(compressionMethod, data);
|
|
||||||
req.headers.emplace_back("Content-Encoding", compressionMethod);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
req.data = std::move(data);
|
req.data = std::move(data);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue