MCPcopy Create free account
hub / github.com/awslabs/aws-lambda-cpp / do_post

Method do_post

src/runtime.cpp:333–387  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

331}
332
333runtime::post_outcome runtime::do_post(
334 std::string const& url,
335 std::string const& request_id,
336 invocation_response const& handler_response)
337{
338 set_curl_post_result_options();
339 curl_easy_setopt(m_curl_handle, CURLOPT_URL, url.c_str());
340 logging::log_info(LOG_TAG, "Making request to %s", url.c_str());
341
342 curl_slist* headers = nullptr;
343 if (handler_response.get_content_type().empty()) {
344 headers = curl_slist_append(headers, "content-type: text/html");
345 }
346 else {
347 headers = curl_slist_append(headers, ("content-type: " + handler_response.get_content_type()).c_str());
348 }
349
350 headers = curl_slist_append(headers, "Expect:");
351 headers = curl_slist_append(headers, "transfer-encoding:");
352 headers = curl_slist_append(headers, m_user_agent_header.c_str());
353 auto const& payload = handler_response.get_payload();
354 logging::log_debug(
355 LOG_TAG, "calculating content length... %s", ("content-length: " + std::to_string(payload.length())).c_str());
356 headers = curl_slist_append(headers, ("content-length: " + std::to_string(payload.length())).c_str());
357
358 std::pair<std::string const&, size_t> ctx{payload, 0};
359 aws::http::response resp;
360 curl_easy_setopt(m_curl_handle, CURLOPT_WRITEDATA, &resp);
361 curl_easy_setopt(m_curl_handle, CURLOPT_HEADERDATA, &resp);
362 curl_easy_setopt(m_curl_handle, CURLOPT_READDATA, &ctx);
363 curl_easy_setopt(m_curl_handle, CURLOPT_HTTPHEADER, headers);
364 CURLcode curl_code = curl_easy_perform(m_curl_handle);
365 curl_slist_free_all(headers);
366
367 if (curl_code != CURLE_OK) {
368 logging::log_debug(
369 LOG_TAG,
370 "CURL returned error code %d - %s, for invocation %s",
371 curl_code,
372 curl_easy_strerror(curl_code),
373 request_id.c_str());
374 return aws::http::response_code::REQUEST_NOT_MADE;
375 }
376
377 long http_response_code;
378 curl_easy_getinfo(m_curl_handle, CURLINFO_RESPONSE_CODE, &http_response_code);
379
380 if (!is_success(aws::http::response_code(http_response_code))) {
381 logging::log_error(
382 LOG_TAG, "Failed to post handler success response. Http response code: %ld.", http_response_code);
383 return aws::http::response_code(http_response_code);
384 }
385
386 return post_outcome(no_result{});
387}
388
389static bool handle_post_outcome(runtime::post_outcome const& o, std::string const& request_id)
390{

Callers

nothing calls this directly

Calls 5

log_infoFunction · 0.85
log_debugFunction · 0.85
is_successFunction · 0.85
response_codeEnum · 0.85
log_errorFunction · 0.85

Tested by

no test coverage detected