@@ -134,27 +134,41 @@ bool HttpBinaryCacheStore::fileExists(const std::string & path)
134134 }
135135}
136136
137- void HttpBinaryCacheStore::upsertFile (
138- const std::string & path, RestartableSource & source, const std::string & mimeType, uint64_t sizeHint)
137+ void HttpBinaryCacheStore::upload (
138+ std::string_view path,
139+ RestartableSource & source,
140+ uint64_t sizeHint,
141+ std::string_view mimeType,
142+ std::optional<std::string_view> contentEncoding)
139143{
140144 auto req = makeRequest (path);
141145 req.method = HttpMethod::PUT;
142- auto compressionMethod = getCompressionMethod (path);
143146
144- std::optional<CompressedSource> compressed;
145-
146- if (compressionMethod) {
147- compressed = CompressedSource (source, *compressionMethod);
148- req.headers .emplace_back (" Content-Encoding" , *compressionMethod);
149- req.data = {compressed->size (), *compressed};
150- } else {
151- req.data = {sizeHint, source};
147+ if (contentEncoding) {
148+ req.headers .emplace_back (" Content-Encoding" , *contentEncoding);
152149 }
153150
151+ req.data = {sizeHint, source};
154152 req.mimeType = mimeType;
155153
154+ getFileTransfer ()->upload (req);
155+ }
156+
157+ void HttpBinaryCacheStore::upload (std::string_view path, CompressedSource & source, std::string_view mimeType)
158+ {
159+ upload (path, static_cast <RestartableSource &>(source), source.size (), mimeType, source.getCompressionMethod ());
160+ }
161+
162+ void HttpBinaryCacheStore::upsertFile (
163+ const std::string & path, RestartableSource & source, const std::string & mimeType, uint64_t sizeHint)
164+ {
156165 try {
157- getFileTransfer ()->upload (req);
166+ if (auto compressionMethod = getCompressionMethod (path)) {
167+ CompressedSource compressed (source, *compressionMethod);
168+ upload (path, compressed, mimeType);
169+ } else {
170+ upload (path, source, sizeHint, mimeType, std::nullopt );
171+ }
158172 } catch (FileTransferError & e) {
159173 UploadToHTTP err (e.message ());
160174 err.addTrace ({}, " while uploading to HTTP binary cache at '%s'" , config->cacheUri .to_string ());
0 commit comments