Skip to content

Integrate POST HTTP request with multi-curl manager #19

@dentiny

Description

@dentiny

unique_ptr<HTTPResponse> Post(PostRequestInfo &info) override {
if (state) {
state->post_count++;
state->total_bytes_sent += info.buffer_in_len;
}
auto curl_headers = TransformHeadersCurl(info.headers);
const string content_type = "Content-Type: application/octet-stream";
curl_headers.Add(content_type.c_str());
// 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());
curl_easy_setopt(*curl, CURLOPT_POST, 1L);
// Set POST body
curl_easy_setopt(*curl, CURLOPT_POSTFIELDS, const_char_ptr_cast(info.buffer_in));
curl_easy_setopt(*curl, CURLOPT_POSTFIELDSIZE, info.buffer_in_len);
// Add headers if any
curl_easy_setopt(*curl, CURLOPT_HTTPHEADER, curl_headers ? curl_headers.headers : nullptr);
// Execute POST request
res = curl->Execute();
}
curl_easy_getinfo(*curl, CURLINFO_RESPONSE_CODE, &request_info->response_code);
info.buffer_out = request_info->body;
// Construct HTTPResponse
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