supported config useSSL

This commit is contained in:
wb-hx510875
2020-07-01 14:08:32 +08:00
committed by Axios
parent 8bed6eecc7
commit 5a451d16d4
6 changed files with 31 additions and 2 deletions

View File

@@ -43,12 +43,16 @@ class ALIBABACLOUD_CORE_EXPORT ClientConfiguration {
void setConnectTimeout(const long connectTimeout);
void setReadTimeout(const long readTimeout);
bool rejectUnauthorized() const;
void setRejectUnauthorized(const bool rejectUnauthorized);
private:
std::string endpoint_;
NetworkProxy proxy_;
std::string regionId_;
long connectTimeout_;
long readTimeout_;
bool rejectUnauthorized_ = true;
};
} // namespace AlibabaCloud

View File

@@ -34,9 +34,12 @@ class HttpClient {
virtual HttpResponseOutcome makeRequest(const HttpRequest &request) = 0;
NetworkProxy proxy()const;
void setProxy(const NetworkProxy &proxy);
bool rejectUnauthorized()const;
void setRejectUnauthorized(const bool &rejectUnauthorized);
private:
NetworkProxy proxy_;
bool rejectUnauthorized_;
};
} // namespace AlibabaCloud
#endif // CORE_INCLUDE_ALIBABACLOUD_CORE_HTTPCLIENT_H_

View File

@@ -71,4 +71,12 @@ void ClientConfiguration::setReadTimeout(const long readTimeout) {
readTimeout_ = readTimeout;
}
bool ClientConfiguration::rejectUnauthorized() const {
return rejectUnauthorized_;
}
void ClientConfiguration::setRejectUnauthorized(const bool rejectUnauthorized) {
rejectUnauthorized_ = rejectUnauthorized;
}
} // namespace AlibabaCloud

View File

@@ -33,6 +33,7 @@ CoreClient::CoreClient(const std::string &servicename,
: serviceName_(servicename), configuration_(configuration),
httpClient_(new CurlHttpClient) {
httpClient_->setProxy(configuration.proxy());
httpClient_->setRejectUnauthorized(configuration.rejectUnauthorized());
}
CoreClient::~CoreClient() { delete httpClient_; }

View File

@@ -163,8 +163,13 @@ CurlHttpClient::makeRequest(const HttpRequest &request) {
}
curl_easy_setopt(curlHandle_, CURLOPT_URL, url.c_str());
curl_easy_setopt(curlHandle_, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(curlHandle_, CURLOPT_SSL_VERIFYHOST, 2L);
if (rejectUnauthorized()) {
curl_easy_setopt(curlHandle_, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(curlHandle_, CURLOPT_SSL_VERIFYHOST, 2L);
} else {
curl_easy_setopt(curlHandle_, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curlHandle_, CURLOPT_SSL_VERIFYHOST, 0L);
}
curl_easy_setopt(curlHandle_, CURLOPT_HEADERDATA, &response);
curl_easy_setopt(curlHandle_, CURLOPT_HEADERFUNCTION, recvHeaders);

View File

@@ -36,4 +36,12 @@ void HttpClient::setProxy(const NetworkProxy &proxy) {
proxy_ = proxy;
}
bool HttpClient::rejectUnauthorized()const{
return rejectUnauthorized_;
}
void HttpClient::setRejectUnauthorized(const bool &rejectUnauthorized) {
rejectUnauthorized_ = rejectUnauthorized;
}
} // namespace AlibabaCloud