diff --git a/http.cpp b/http.cpp index 8eaaa2e..790add7 100644 --- a/http.cpp +++ b/http.cpp @@ -64,12 +64,14 @@ response request::execute() { detail::check_init(); std::string str; + curl_easy_setopt(m_curl, CURLOPT_NOSIGNAL, 1L); curl_easy_setopt(m_curl, CURLOPT_CUSTOMREQUEST, m_method); curl_easy_setopt(m_curl, CURLOPT_URL, m_url.c_str()); curl_easy_setopt(m_curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, detail::curl_write_data_callback); curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, &str); curl_easy_setopt(m_curl, CURLOPT_ERRORBUFFER, m_error_buf); + m_error_buf[0] = '\0'; if (m_header_list != nullptr) curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER, m_header_list); @@ -81,7 +83,7 @@ response request::execute() { return response; } - int response_code = 0; + long response_code = 0; curl_easy_getinfo(m_curl, CURLINFO_RESPONSE_CODE, &response_code); auto response = detail::make_response(m_url, response_code); @@ -95,10 +97,10 @@ void request::prepare() { } namespace detail { - size_t curl_write_data_callback(void *ptr, size_t size, size_t nmemb, std::string *outstr) { - auto new_length = size * nmemb; - outstr->append(reinterpret_cast(ptr), new_length); - return new_length; + size_t curl_write_data_callback(void *ptr, size_t size, size_t nmemb, void *userdata) { + const size_t n = size * nmemb; + static_cast(userdata)->append(static_cast(ptr), n); + return n; } response make_response(const std::string &url, int code) { diff --git a/http.hpp b/http.hpp index d18ccf0..c2e2765 100644 --- a/http.hpp +++ b/http.hpp @@ -121,7 +121,7 @@ private: using response_type = response; namespace detail { - size_t curl_write_data_callback(void *ptr, size_t size, size_t nmemb, std::string *outstr); + size_t curl_write_data_callback(void *ptr, size_t size, size_t nmemb, void *userdata); response make_response(const std::string &url, int code); void check_init();