input/curl: move code to CreateEasy()
This commit is contained in:
parent
fb2e0f734e
commit
e831af35fd
|
@ -455,54 +455,62 @@ CurlInputStream::~CurlInputStream() noexcept
|
||||||
FreeEasyIndirect();
|
FreeEasyIndirect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static CurlEasy
|
||||||
CurlInputStream::InitEasy()
|
CreateEasy(const char *url)
|
||||||
{
|
{
|
||||||
request = new CurlRequest(**curl_init, GetURI(), *this);
|
CurlEasy easy{url};
|
||||||
|
|
||||||
request->SetOption(CURLOPT_HTTP200ALIASES, http_200_aliases);
|
easy.SetOption(CURLOPT_HTTP200ALIASES, http_200_aliases);
|
||||||
request->SetOption(CURLOPT_FOLLOWLOCATION, 1L);
|
easy.SetOption(CURLOPT_FOLLOWLOCATION, 1L);
|
||||||
request->SetOption(CURLOPT_MAXREDIRS, 5L);
|
easy.SetOption(CURLOPT_MAXREDIRS, 5L);
|
||||||
|
|
||||||
/* this option eliminates the probe request when
|
/* this option eliminates the probe request when
|
||||||
username/password are specified */
|
username/password are specified */
|
||||||
request->SetOption(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
easy.SetOption(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||||
|
|
||||||
if (proxy != nullptr)
|
if (proxy != nullptr)
|
||||||
request->SetOption(CURLOPT_PROXY, proxy);
|
easy.SetOption(CURLOPT_PROXY, proxy);
|
||||||
|
|
||||||
if (proxy_port > 0)
|
if (proxy_port > 0)
|
||||||
request->SetOption(CURLOPT_PROXYPORT, (long)proxy_port);
|
easy.SetOption(CURLOPT_PROXYPORT, (long)proxy_port);
|
||||||
|
|
||||||
if (proxy_user != nullptr && proxy_password != nullptr)
|
if (proxy_user != nullptr && proxy_password != nullptr)
|
||||||
request->SetOption(CURLOPT_PROXYUSERPWD,
|
easy.SetOption(CURLOPT_PROXYUSERPWD,
|
||||||
FmtBuffer<1024>("{}:{}", proxy_user,
|
FmtBuffer<1024>("{}:{}", proxy_user,
|
||||||
proxy_password).c_str());
|
proxy_password).c_str());
|
||||||
|
|
||||||
if (cacert != nullptr)
|
if (cacert != nullptr)
|
||||||
request->SetOption(CURLOPT_CAINFO, cacert);
|
easy.SetOption(CURLOPT_CAINFO, cacert);
|
||||||
request->SetVerifyPeer(verify_peer);
|
easy.SetVerifyPeer(verify_peer);
|
||||||
request->SetVerifyHost(verify_host);
|
easy.SetVerifyHost(verify_host);
|
||||||
request->SetOption(CURLOPT_HTTPHEADER, request_headers.Get());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
request->SetProxyVerifyPeer(verify_peer);
|
easy.SetProxyVerifyPeer(verify_peer);
|
||||||
request->SetProxyVerifyHost(verify_host);
|
easy.SetProxyVerifyHost(verify_host);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
/* these methods fail if libCURL was compiled with
|
/* these methods fail if libCURL was compiled with
|
||||||
CURL_DISABLE_PROXY; ignore silently */
|
CURL_DISABLE_PROXY; ignore silently */
|
||||||
}
|
}
|
||||||
|
|
||||||
request->SetConnectTimeout(connect_timeout);
|
easy.SetConnectTimeout(connect_timeout);
|
||||||
|
|
||||||
request->SetOption(CURLOPT_VERBOSE, verbose ? 1 : 0);
|
easy.SetOption(CURLOPT_VERBOSE, verbose ? 1 : 0);
|
||||||
|
|
||||||
request->SetOption(CURLOPT_LOW_SPEED_LIMIT, low_speed_limit);
|
easy.SetOption(CURLOPT_LOW_SPEED_LIMIT, low_speed_limit);
|
||||||
request->SetOption(CURLOPT_LOW_SPEED_TIME, low_speed_time);
|
easy.SetOption(CURLOPT_LOW_SPEED_TIME, low_speed_time);
|
||||||
|
|
||||||
request->SetOption(CURLOPT_TCP_KEEPALIVE, tcp_keepalive ? 1 : 0);
|
easy.SetOption(CURLOPT_TCP_KEEPALIVE, tcp_keepalive ? 1 : 0);
|
||||||
request->SetOption(CURLOPT_TCP_KEEPIDLE, tcp_keepidle);
|
easy.SetOption(CURLOPT_TCP_KEEPIDLE, tcp_keepidle);
|
||||||
request->SetOption(CURLOPT_TCP_KEEPINTVL, tcp_keepintvl);
|
easy.SetOption(CURLOPT_TCP_KEEPINTVL, tcp_keepintvl);
|
||||||
|
|
||||||
|
return easy;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurlInputStream::InitEasy()
|
||||||
|
{
|
||||||
|
request = new CurlRequest(**curl_init, CreateEasy(GetURI()), *this);
|
||||||
|
request->SetRequestHeaders(request_headers.Get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -125,6 +125,14 @@ public:
|
||||||
SetOption(CURLOPT_SSL_VERIFYPEER, (long)value);
|
SetOption(CURLOPT_SSL_VERIFYPEER, (long)value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetProxyVerifyHost(bool value) {
|
||||||
|
SetOption(CURLOPT_PROXY_SSL_VERIFYHOST, value ? 2L : 0L);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetProxyVerifyPeer(bool value) {
|
||||||
|
SetOption(CURLOPT_PROXY_SSL_VERIFYPEER, value);
|
||||||
|
}
|
||||||
|
|
||||||
void SetConnectTimeout(long timeout) {
|
void SetConnectTimeout(long timeout) {
|
||||||
SetOption(CURLOPT_CONNECTTIMEOUT, timeout);
|
SetOption(CURLOPT_CONNECTTIMEOUT, timeout);
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,38 +97,6 @@ public:
|
||||||
easy.SetRequestHeaders(request_headers);
|
easy.SetRequestHeaders(request_headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetVerifyHost(bool value) {
|
|
||||||
easy.SetVerifyHost(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetVerifyPeer(bool value) {
|
|
||||||
easy.SetVerifyPeer(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetProxyVerifyHost(bool value) {
|
|
||||||
easy.SetOption(CURLOPT_PROXY_SSL_VERIFYHOST, value ? 2L : 0L);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetProxyVerifyPeer(bool value) {
|
|
||||||
easy.SetOption(CURLOPT_PROXY_SSL_VERIFYPEER, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetConnectTimeout(long timeout_seconds) {
|
|
||||||
easy.SetConnectTimeout(timeout_seconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetNoBody(bool value=true) {
|
|
||||||
easy.SetNoBody(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetPost(bool value=true) {
|
|
||||||
easy.SetPost(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetRequestBody(const void *data, std::size_t size) {
|
|
||||||
easy.SetRequestBody(data, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Resume() noexcept;
|
void Resume() noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue