Skip to content

Ranged PUT request with CURLOPT_RESUME_FROM does not work #8969

@simon-berger

Description

@simon-berger

I did this

I wanted to do a ranged put request as described here.

// Setup curl
std::shared_ptr<CurlHolder> curl_(new CurlHolder());

// Set request url
std::string url{"http://httpbin.org/put"};
curl_easy_setopt(curl_->handle, CURLOPT_URL, url.c_str());

// Set payload
std::string body{"world"};
curl_easy_setopt(curl_->handle, CURLOPT_POSTFIELDSIZE_LARGE, static_cast<curl_off_t>(body.length()));
curl_easy_setopt(curl_->handle, CURLOPT_COPYPOSTFIELDS, body.c_str());

// Upload byte 6 to 10 of string "hello world" -> "world" (5 bytes) using a ranged PUT request
// Range values
curl_off_t resume_from = static_cast<curl_off_t>(6);
curl_off_t filesize = static_cast<curl_off_t>(11);

// Create custom Content-Range header described in https://curl.se/mail/lib-2019-05/0012.html
constexpr int max_header_char_count{256};
std::array<char, max_header_char_count> range_header{};
sprintf(range_header.data(),
        "Content-Range: bytes %" CURL_FORMAT_CURL_OFF_T
        "-"
        "%" CURL_FORMAT_CURL_OFF_T "/*",                      /**/
        resume_from, filesize - 1);
std::string range_header_str = std::string(range_header.data());
curl_slist* chunk = nullptr;
chunk = curl_slist_append(chunk, range_header_str.c_str());
curl_easy_setopt(curl_->handle, CURLOPT_HTTPHEADER, chunk);
curl_slist_free_all(curl_->chunk);
curl_->chunk = chunk;

// Set range values
curl_easy_setopt(curl_->handle, CURLOPT_RESUME_FROM_LARGE, resume_from);
curl_easy_setopt(curl_->handle, CURLOPT_INFILESIZE_LARGE, filesize);

// Perform PUT request
curl_easy_setopt(curl_->handle, CURLOPT_CUSTOMREQUEST, "PUT");
curl_easy_perform(curl_->handle);

I expected the following

Execute a PUT request to the given server url with an upload range.

Actual behavior

No HTTP request is executed (checked with Wireshark) and instead, the execution of the program is stuck at curl_easy_perform(curl_->handle). The request is only executed if I comment / remove curl_easy_setopt(curl_->handle, CURLOPT_RESUME_FROM_LARGE, resume_from which results in disabling the resume from option.
Note: The request is also executed if I remove the body.

What I have tried to fix the problem

curl/libcurl version

curl-7.83.1
Same problem with curl-7.81.0 which I have used before i encountered the problem.

operating system

Ubuntu 20.04.4 LTS
Linux Simon-PC 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions