Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECKIT-619 Enable PUT method on EasyCURL #81

Merged
merged 4 commits into from
Nov 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions src/eckit/io/EasyCURL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -933,14 +933,31 @@ EasyCURLResponse EasyCURL::POST(const std::string& url, const std::string& data)
return request(url);
}

namespace {

/**
* Copies the content from input `userdata` into output `buffer`
*
* Returns the number of characters copied
*/
size_t readCallback(char* buffer, size_t size [[maybe_unused]], size_t nitems [[maybe_unused]], void* userdata) {
auto data = static_cast<std::string*>(userdata);

data->copy(buffer, data->size());
return data->size();
}

} // namespace

EasyCURLResponse EasyCURL::PUT(const std::string& url, const std::string& data) {
NOTIMP;
// Disable unreachable code
#if 0
_(curl_easy_setopt(ch_->curl_, CURLOPT_CUSTOMREQUEST, NULL));
_(curl_easy_setopt(ch_->curl_, CURLOPT_PUT, 1L));
_(curl_easy_setopt(ch_->curl_, CURLOPT_UPLOAD, 1L));

// Setup callback to read PUT request body (i.e. copy the given 'data' into an internal 'buffer')
_(curl_easy_setopt(ch_->curl_, CURLOPT_READFUNCTION, readCallback));
_(curl_easy_setopt(ch_->curl_, CURLOPT_READDATA, &data));
_(curl_easy_setopt(ch_->curl_, CURLOPT_INFILESIZE, data.size()));

return request(url);
#endif
}

EasyCURLResponse EasyCURL::DELETE(const std::string& url) {
Expand Down
Loading