This commit is contained in:
Jinming Hu 2020-03-05 14:13:02 +08:00 коммит произвёл Vincent Jiang (LEI)
Родитель 4486a450dc
Коммит efd10e6cb5
2 изменённых файлов: 30 добавлений и 15 удалений

Просмотреть файл

@ -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<CURL *> m_handles;
std::mutex m_handles_mutex;
std::condition_variable m_cv;

Просмотреть файл

@ -4,19 +4,13 @@
#include "constants.h"
namespace azure { namespace storage_lite {
namespace azure { namespace storage_lite {
CurlEasyRequest::CurlEasyRequest(std::shared_ptr<CurlEasyClient> 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;