From 51c95dd764486d8155cdb5ee72d73d35aabb3f44 Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Sun, 3 Oct 2021 17:43:29 +0530 Subject: [PATCH] Handle null header in leader curl response. --- src/http_client.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/http_client.cpp b/src/http_client.cpp index 10a3d061..eafc9777 100644 --- a/src/http_client.cpp +++ b/src/http_client.cpp @@ -136,8 +136,10 @@ long HttpClient::perform_curl(CURL *curl, std::map& re void HttpClient::extract_response_headers(CURL* curl, std::map &res_headers) { char* content_type; - curl_easy_getinfo (curl, CURLINFO_CONTENT_TYPE, &content_type); - res_headers.emplace("content-type", content_type); + CURLcode res = curl_easy_getinfo (curl, CURLINFO_CONTENT_TYPE, &content_type); + if(res == CURLE_OK && content_type != nullptr) { + res_headers.emplace("content-type", content_type); + } } size_t HttpClient::curl_req_send_callback(char* buffer, size_t size, size_t nitems, void* userdata) { @@ -204,13 +206,16 @@ size_t HttpClient::curl_write_async(char *buffer, size_t size, size_t nmemb, voi if(req_res->res->status_code == 0) { CURL* curl = req_res->req->data; long http_code = 500; - curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code); + CURLcode res = curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code); + if(res == CURLE_OK) { + req_res->res->status_code = http_code; + } char* content_type; - curl_easy_getinfo (curl, CURLINFO_CONTENT_TYPE, &content_type); - - req_res->res->status_code = http_code; - req_res->res->content_type_header = content_type; + res = curl_easy_getinfo (curl, CURLINFO_CONTENT_TYPE, &content_type); + if(res == CURLE_OK && content_type != nullptr) { + req_res->res->content_type_header = content_type; + } } // we've got response from remote host: write to client and ask for more request body