Skip to content

Integrate PUT HTTP request with multi-curl manager #17

@dentiny

Description

@dentiny

unique_ptr<HTTPResponse> Put(PutRequestInfo &info) override {
if (state) {
state->put_count++;
state->total_bytes_sent += info.buffer_in_len;
}
auto curl_headers = TransformHeadersCurl(info.headers);
// Add content type header from info
curl_headers.Add("Content-Type: " + info.content_type);
// transform parameters
request_info->url = info.url;
if (!info.params.extra_headers.empty()) {
auto curl_params = TransformParamsCurl(info.params);
request_info->url += "?" + curl_params;
}
CURLcode res;
{
curl_easy_setopt(*curl, CURLOPT_URL, request_info->url.c_str());
// Perform PUT
curl_easy_setopt(*curl, CURLOPT_CUSTOMREQUEST, "PUT");
// Include PUT body
curl_easy_setopt(*curl, CURLOPT_POSTFIELDS, const_char_ptr_cast(info.buffer_in));
curl_easy_setopt(*curl, CURLOPT_POSTFIELDSIZE, info.buffer_in_len);
// Apply headers
curl_easy_setopt(*curl, CURLOPT_HTTPHEADER, curl_headers ? curl_headers.headers : nullptr);
res = curl->Execute();
}
curl_easy_getinfo(*curl, CURLINFO_RESPONSE_CODE, &request_info->response_code);
return TransformResponseCurl(res);
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions