in src/runtime.cpp [325:379]
runtime::post_outcome runtime::do_post(
std::string const& url,
std::string const& request_id,
invocation_response const& handler_response)
{
set_curl_post_result_options();
curl_easy_setopt(m_curl_handle, CURLOPT_URL, url.c_str());
logging::log_info(LOG_TAG, "Making request to %s", url.c_str());
curl_slist* headers = nullptr;
if (handler_response.get_content_type().empty()) {
headers = curl_slist_append(headers, "content-type: text/html");
}
else {
headers = curl_slist_append(headers, ("content-type: " + handler_response.get_content_type()).c_str());
}
headers = curl_slist_append(headers, "Expect:");
headers = curl_slist_append(headers, "transfer-encoding:");
headers = curl_slist_append(headers, m_user_agent_header.c_str());
auto const& payload = handler_response.get_payload();
logging::log_debug(
LOG_TAG, "calculating content length... %s", ("content-length: " + std::to_string(payload.length())).c_str());
headers = curl_slist_append(headers, ("content-length: " + std::to_string(payload.length())).c_str());
std::pair<std::string const&, size_t> ctx{payload, 0};
aws::http::response resp;
curl_easy_setopt(m_curl_handle, CURLOPT_WRITEDATA, &resp);
curl_easy_setopt(m_curl_handle, CURLOPT_HEADERDATA, &resp);
curl_easy_setopt(m_curl_handle, CURLOPT_READDATA, &ctx);
curl_easy_setopt(m_curl_handle, CURLOPT_HTTPHEADER, headers);
CURLcode curl_code = curl_easy_perform(m_curl_handle);
curl_slist_free_all(headers);
if (curl_code != CURLE_OK) {
logging::log_debug(
LOG_TAG,
"CURL returned error code %d - %s, for invocation %s",
curl_code,
curl_easy_strerror(curl_code),
request_id.c_str());
return aws::http::response_code::REQUEST_NOT_MADE;
}
long http_response_code;
curl_easy_getinfo(m_curl_handle, CURLINFO_RESPONSE_CODE, &http_response_code);
if (!is_success(aws::http::response_code(http_response_code))) {
logging::log_error(
LOG_TAG, "Failed to post handler success response. Http response code: %ld.", http_response_code);
return aws::http::response_code(http_response_code);
}
return post_outcome(no_result{});
}