Add headers to answer_type.

This commit is contained in:
tastytea 2020-01-05 12:03:23 +01:00
parent 96e9d9a9fd
commit 9c279822b2
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
3 changed files with 22 additions and 2 deletions

View File

@ -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.

View File

@ -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.
*

View File

@ -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",