From 9c279822b2d650104d39912ad2cc7907cc2cd2f3 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 5 Jan 2020 12:03:23 +0100 Subject: [PATCH] Add headers to answer_type. --- include/curl_wrapper.hpp | 3 ++- include/return_types.hpp | 10 ++++++++++ src/curl_wrapper.cpp | 11 ++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/curl_wrapper.hpp b/include/curl_wrapper.hpp index c98a6a9..f00388c 100644 --- a/include/curl_wrapper.hpp +++ b/include/curl_wrapper.hpp @@ -96,7 +96,8 @@ public: private: CURL *_connection; char _curl_buffer_error[CURL_ERROR_SIZE]; - string _curl_buffer; + string _curl_buffer_headers; + string _curl_buffer_body; /*! * @brief libcurl write callback function. diff --git a/include/return_types.hpp b/include/return_types.hpp index 2913be0..f0e1e02 100644 --- a/include/return_types.hpp +++ b/include/return_types.hpp @@ -48,18 +48,28 @@ struct answer_type * @since 0.1.0 */ uint8_t curl_error_code; + /*! * @brief The error message. * * @since 0.1.0 */ string error_message; + /*! * @brief HTTP status code. * * @since 0.1.0 */ uint16_t http_status; + + /*! + * @brief The headers of the response from the server. + * + * @since 0.1.0 + */ + string headers; + /*! * @brief The response from the server, usually JSON. * diff --git a/src/curl_wrapper.cpp b/src/curl_wrapper.cpp index ac534bb..5d04d38 100644 --- a/src/curl_wrapper.cpp +++ b/src/curl_wrapper.cpp @@ -113,7 +113,16 @@ void CURLWrapper::setup_curl() } // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) - code = curl_easy_setopt(_connection, CURLOPT_WRITEDATA, &_curl_buffer); + code = curl_easy_setopt(_connection, CURLOPT_HEADERDATA, + &_curl_buffer_headers); + if (code != CURLE_OK) + { + throw CURLException{code, "Failed to set header data", + _curl_buffer_error}; + } + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) + code = curl_easy_setopt(_connection, CURLOPT_WRITEDATA, &_curl_buffer_body); if (code != CURLE_OK) { throw CURLException{code, "Failed to set write data",