diff options
Diffstat (limited to 'src/common/linux/libcurl_wrapper.cc')
-rw-r--r-- | src/common/linux/libcurl_wrapper.cc | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/common/linux/libcurl_wrapper.cc b/src/common/linux/libcurl_wrapper.cc index 4ff9bb01..fd4e34cd 100644 --- a/src/common/linux/libcurl_wrapper.cc +++ b/src/common/linux/libcurl_wrapper.cc @@ -110,7 +110,9 @@ static size_t WriteCallback(void *ptr, size_t size, bool LibcurlWrapper::SendRequest(const string& url, const std::map<string, string>& parameters, - string* server_response) { + int* http_status_code, + string* http_header_data, + string* http_response_data) { (*easy_setopt_)(curl_, CURLOPT_URL, url.c_str()); std::map<string, string>::const_iterator iter = parameters.begin(); for (; iter != parameters.end(); ++iter) @@ -120,10 +122,17 @@ bool LibcurlWrapper::SendRequest(const string& url, CURLFORM_END); (*easy_setopt_)(curl_, CURLOPT_HTTPPOST, formpost_); - if (server_response != NULL) { + if (http_response_data != NULL) { + http_response_data->clear(); (*easy_setopt_)(curl_, CURLOPT_WRITEFUNCTION, WriteCallback); (*easy_setopt_)(curl_, CURLOPT_WRITEDATA, - reinterpret_cast<void *>(server_response)); + reinterpret_cast<void *>(http_response_data)); + } + if (http_header_data != NULL) { + http_header_data->clear(); + (*easy_setopt_)(curl_, CURLOPT_HEADERFUNCTION, WriteCallback); + (*easy_setopt_)(curl_, CURLOPT_HEADERDATA, + reinterpret_cast<void *>(http_header_data)); } CURLcode err_code = CURLE_OK; @@ -131,6 +140,10 @@ bool LibcurlWrapper::SendRequest(const string& url, easy_strerror_ = reinterpret_cast<const char* (*)(CURLcode)> (dlsym(curl_lib_, "curl_easy_strerror")); + if (http_status_code != NULL) { + (*easy_getinfo_)(curl_, CURLINFO_RESPONSE_CODE, http_status_code); + } + #ifndef NDEBUG if (err_code != CURLE_OK) fprintf(stderr, "Failed to send http request to %s, error: %s\n", @@ -211,6 +224,10 @@ bool LibcurlWrapper::SetFunctionPointers() { "curl_easy_cleanup", void(*)(CURL*)); + SET_AND_CHECK_FUNCTION_POINTER(easy_getinfo_, + "curl_easy_getinfo", + CURLcode(*)(CURL *, CURLINFO info, ...)); + SET_AND_CHECK_FUNCTION_POINTER(slist_free_all_, "curl_slist_free_all", void(*)(curl_slist*)); |