| 228 | } |
| 229 | |
| 230 | runtime::next_outcome runtime::get_next() |
| 231 | { |
| 232 | http::response resp; |
| 233 | set_curl_next_options(); |
| 234 | curl_easy_setopt(m_curl_handle, CURLOPT_WRITEDATA, &resp); |
| 235 | curl_easy_setopt(m_curl_handle, CURLOPT_HEADERDATA, &resp); |
| 236 | |
| 237 | curl_slist* headers = nullptr; |
| 238 | headers = curl_slist_append(headers, m_user_agent_header.c_str()); |
| 239 | curl_easy_setopt(m_curl_handle, CURLOPT_HTTPHEADER, headers); |
| 240 | |
| 241 | logging::log_debug(LOG_TAG, "Making request to %s", m_endpoints[Endpoints::NEXT].c_str()); |
| 242 | CURLcode curl_code = curl_easy_perform(m_curl_handle); |
| 243 | logging::log_debug(LOG_TAG, "Completed request to %s", m_endpoints[Endpoints::NEXT].c_str()); |
| 244 | curl_slist_free_all(headers); |
| 245 | |
| 246 | if (curl_code != CURLE_OK) { |
| 247 | logging::log_debug(LOG_TAG, "CURL returned error code %d - %s", curl_code, curl_easy_strerror(curl_code)); |
| 248 | logging::log_error( |
| 249 | LOG_TAG, |
| 250 | "Failed to get next invocation. No Response from endpoint \"%s\"", |
| 251 | m_endpoints[Endpoints::NEXT].c_str()); |
| 252 | return aws::http::response_code::REQUEST_NOT_MADE; |
| 253 | } |
| 254 | |
| 255 | { |
| 256 | long resp_code; |
| 257 | curl_easy_getinfo(m_curl_handle, CURLINFO_RESPONSE_CODE, &resp_code); |
| 258 | resp.set_response_code(static_cast<aws::http::response_code>(resp_code)); |
| 259 | } |
| 260 | |
| 261 | { |
| 262 | char* content_type = nullptr; |
| 263 | curl_easy_getinfo(m_curl_handle, CURLINFO_CONTENT_TYPE, &content_type); |
| 264 | resp.set_content_type(content_type); |
| 265 | } |
| 266 | |
| 267 | if (!is_success(resp.get_response_code())) { |
| 268 | logging::log_error( |
| 269 | LOG_TAG, |
| 270 | "Failed to get next invocation. Http Response code: %d", |
| 271 | static_cast<int>(resp.get_response_code())); |
| 272 | return resp.get_response_code(); |
| 273 | } |
| 274 | |
| 275 | auto out = resp.get_header(REQUEST_ID_HEADER); |
| 276 | if (!out.is_success()) { |
| 277 | logging::log_error(LOG_TAG, "Failed to find header %s in response", REQUEST_ID_HEADER); |
| 278 | return aws::http::response_code::REQUEST_NOT_MADE; |
| 279 | } |
| 280 | invocation_request req; |
| 281 | req.payload = resp.get_body(); |
| 282 | req.request_id = std::move(out).get_result(); |
| 283 | |
| 284 | out = resp.get_header(TRACE_ID_HEADER); |
| 285 | if (out.is_success()) { |
| 286 | req.xray_trace_id = std::move(out).get_result(); |
| 287 | } |
no test coverage detected