1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

Merge pull request #14407 from NixOS/fix-upload-put-http

libstore/filetransfer: Add HttpMethod::PUT
This commit is contained in:
Sergei Zimmerman 2025-10-29 03:24:10 +00:00 committed by GitHub
commit 194c21fc82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 8 additions and 2 deletions

View file

@ -394,9 +394,11 @@ struct curlFileTransfer : public FileTransfer
if (request.method == HttpMethod::POST) { if (request.method == HttpMethod::POST) {
curl_easy_setopt(req, CURLOPT_POST, 1L); curl_easy_setopt(req, CURLOPT_POST, 1L);
curl_easy_setopt(req, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t) request.data->length()); curl_easy_setopt(req, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t) request.data->length());
} else { } else if (request.method == HttpMethod::PUT) {
curl_easy_setopt(req, CURLOPT_UPLOAD, 1L); curl_easy_setopt(req, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(req, CURLOPT_INFILESIZE_LARGE, (curl_off_t) request.data->length()); curl_easy_setopt(req, CURLOPT_INFILESIZE_LARGE, (curl_off_t) request.data->length());
} else {
unreachable();
} }
curl_easy_setopt(req, CURLOPT_READFUNCTION, readCallbackWrapper); curl_easy_setopt(req, CURLOPT_READFUNCTION, readCallbackWrapper);
curl_easy_setopt(req, CURLOPT_READDATA, this); curl_easy_setopt(req, CURLOPT_READDATA, this);

View file

@ -141,7 +141,7 @@ void HttpBinaryCacheStore::upsertFile(
uint64_t sizeHint) uint64_t sizeHint)
{ {
auto req = makeRequest(path); auto req = makeRequest(path);
req.method = HttpMethod::PUT;
auto data = StreamToSourceAdapter(istream).drain(); auto data = StreamToSourceAdapter(istream).drain();
auto compressionMethod = getCompressionMethod(path); auto compressionMethod = getCompressionMethod(path);

View file

@ -88,6 +88,7 @@ extern const unsigned int RETRY_TIME_MS_DEFAULT;
*/ */
enum struct HttpMethod { enum struct HttpMethod {
GET, GET,
PUT,
HEAD, HEAD,
POST, POST,
DELETE, DELETE,
@ -147,7 +148,9 @@ struct FileTransferRequest
case HttpMethod::HEAD: case HttpMethod::HEAD:
case HttpMethod::GET: case HttpMethod::GET:
return "download"; return "download";
case HttpMethod::PUT:
case HttpMethod::POST: case HttpMethod::POST:
assert(data);
return "upload"; return "upload";
case HttpMethod::DELETE: case HttpMethod::DELETE:
return "delet"; return "delet";

View file

@ -101,6 +101,7 @@ std::string
S3BinaryCacheStore::uploadPart(std::string_view key, std::string_view uploadId, uint64_t partNumber, std::string data) S3BinaryCacheStore::uploadPart(std::string_view key, std::string_view uploadId, uint64_t partNumber, std::string data)
{ {
auto req = makeRequest(key); auto req = makeRequest(key);
req.method = HttpMethod::PUT;
req.setupForS3(); req.setupForS3();
auto url = req.uri.parsed(); auto url = req.uri.parsed();