diff --git a/include/http/libcurl_http_client.h b/include/http/libcurl_http_client.h index fe7eb14..23f302b 100644 --- a/include/http/libcurl_http_client.h +++ b/include/http/libcurl_http_client.h @@ -334,10 +334,10 @@ namespace azure { namespace storage_lite { return res; } - const std::string& get_capath(void) - { - return m_capath; - } + const std::string& get_capath() + { + return m_capath; + } void release_handle(CURL *h) { @@ -346,9 +346,20 @@ namespace azure { namespace storage_lite { m_cv.notify_one(); } + void set_proxy(std::string proxy) + { + m_proxy = std::move(proxy); + } + + const std::string& get_proxy() const + { + return m_proxy; + } + private: int m_size; std::string m_capath; + std::string m_proxy; std::queue m_handles; std::mutex m_handles_mutex; std::condition_variable m_cv; diff --git a/src/http/libcurl_http_client.cpp b/src/http/libcurl_http_client.cpp index 836d7f3..f03c967 100644 --- a/src/http/libcurl_http_client.cpp +++ b/src/http/libcurl_http_client.cpp @@ -4,19 +4,13 @@ #include "constants.h" -namespace azure { namespace storage_lite { +namespace azure { namespace storage_lite { CurlEasyRequest::CurlEasyRequest(std::shared_ptr client, CURL *h) - : m_client(client), - m_curl(h), - m_slist(NULL) + : m_client(client), m_curl(h), m_slist(NULL) { check_code(curl_easy_setopt(m_curl, CURLOPT_HEADERFUNCTION, header_callback)); check_code(curl_easy_setopt(m_curl, CURLOPT_HEADERDATA, this)); - if (!m_client->get_capath().empty()) - { - check_code(curl_easy_setopt(m_curl, CURLOPT_CAINFO, m_client->get_capath().data())); - } } CurlEasyRequest::~CurlEasyRequest() @@ -39,10 +33,10 @@ namespace azure { namespace storage_lite { switch (m_method) { case http_method::get: - check_code(curl_easy_setopt(m_curl, CURLOPT_HTTPGET, 1)); + check_code(curl_easy_setopt(m_curl, CURLOPT_HTTPGET, 1L)); break; case http_method::put: - check_code(curl_easy_setopt(m_curl, CURLOPT_UPLOAD, 1)); + check_code(curl_easy_setopt(m_curl, CURLOPT_UPLOAD, 1L)); break; case http_method::del: check_code(curl_easy_setopt(m_curl, CURLOPT_CUSTOMREQUEST, constants::http_delete)); @@ -55,7 +49,7 @@ namespace azure { namespace storage_lite { check_code(curl_easy_setopt(m_curl, CURLOPT_CUSTOMREQUEST, constants::http_post)); break; case http_method::patch: - check_code(curl_easy_setopt(m_curl, CURLOPT_UPLOAD, 1)); + check_code(curl_easy_setopt(m_curl, CURLOPT_UPLOAD, 1L)); check_code(curl_easy_setopt(m_curl, CURLOPT_CUSTOMREQUEST, constants::http_patch)); break; } @@ -66,6 +60,16 @@ namespace azure { namespace storage_lite { m_slist = curl_slist_append(m_slist, "Expect:"); check_code(curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER, m_slist)); + if (!m_client->get_capath().empty()) + { + check_code(curl_easy_setopt(m_curl, CURLOPT_CAINFO, m_client->get_capath().data())); + } + + if (!m_client->get_proxy().empty()) + { + check_code(curl_easy_setopt(m_curl, CURLOPT_PROXY, m_client->get_proxy().data())); + } + const auto result = curl_easy_perform(m_curl); check_code(result); // has nothing to do with checks, just resets errno for succeeded ops. return result;