Skip to content

Commit 194c21f

Browse files
authored
Merge pull request #14407 from NixOS/fix-upload-put-http
libstore/filetransfer: Add HttpMethod::PUT
2 parents e08853a + ae49074 commit 194c21f

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

src/libstore/filetransfer.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,11 @@ struct curlFileTransfer : public FileTransfer
394394
if (request.method == HttpMethod::POST) {
395395
curl_easy_setopt(req, CURLOPT_POST, 1L);
396396
curl_easy_setopt(req, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t) request.data->length());
397-
} else {
397+
} else if (request.method == HttpMethod::PUT) {
398398
curl_easy_setopt(req, CURLOPT_UPLOAD, 1L);
399399
curl_easy_setopt(req, CURLOPT_INFILESIZE_LARGE, (curl_off_t) request.data->length());
400+
} else {
401+
unreachable();
400402
}
401403
curl_easy_setopt(req, CURLOPT_READFUNCTION, readCallbackWrapper);
402404
curl_easy_setopt(req, CURLOPT_READDATA, this);

src/libstore/http-binary-cache-store.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void HttpBinaryCacheStore::upsertFile(
141141
uint64_t sizeHint)
142142
{
143143
auto req = makeRequest(path);
144-
144+
req.method = HttpMethod::PUT;
145145
auto data = StreamToSourceAdapter(istream).drain();
146146

147147
auto compressionMethod = getCompressionMethod(path);

src/libstore/include/nix/store/filetransfer.hh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ extern const unsigned int RETRY_TIME_MS_DEFAULT;
8888
*/
8989
enum struct HttpMethod {
9090
GET,
91+
PUT,
9192
HEAD,
9293
POST,
9394
DELETE,
@@ -147,7 +148,9 @@ struct FileTransferRequest
147148
case HttpMethod::HEAD:
148149
case HttpMethod::GET:
149150
return "download";
151+
case HttpMethod::PUT:
150152
case HttpMethod::POST:
153+
assert(data);
151154
return "upload";
152155
case HttpMethod::DELETE:
153156
return "delet";

src/libstore/s3-binary-cache-store.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ std::string
101101
S3BinaryCacheStore::uploadPart(std::string_view key, std::string_view uploadId, uint64_t partNumber, std::string data)
102102
{
103103
auto req = makeRequest(key);
104+
req.method = HttpMethod::PUT;
104105
req.setupForS3();
105106

106107
auto url = req.uri.parsed();

0 commit comments

Comments
 (0)