Skip to content

Commit

Permalink
fix https (#5283)
Browse files Browse the repository at this point in the history
  • Loading branch information
cangfengzhs committed Jan 29, 2023
1 parent 211e4e7 commit 69ee505
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/common/http/HttpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ HttpResponse HttpClient::sendRequest(const std::string& url,
CURL* curl = curl_easy_init();
CHECK(curl);
setUrl(curl, url);
if (folly::StringPiece(url).startsWith("https")) {
setSSL(curl);
}
setMethod(curl, method);
curl_slist* h = setHeaders(curl, header);
if (!body.empty()) {
Expand Down Expand Up @@ -156,6 +159,11 @@ void HttpClient::setAuth(CURL* curl, const std::string& username, const std::str
}
}

void HttpClient::setSSL(CURL* curl) {
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
}

size_t HttpClient::onWriteData(void* ptr, size_t size, size_t nmemb, void* stream) {
if (ptr == nullptr || size == 0) {
return 0;
Expand Down
1 change: 1 addition & 0 deletions src/common/http/HttpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class HttpClient {
static void setRespBody(CURL* curl, const std::string& body);
static void setRespHeader(CURL* curl, const std::string& header);
static void setTimeout(CURL* curl);
static void setSSL(CURL* curl);
static void setAuth(CURL* curl, const std::string& username, const std::string& password);
static size_t onWriteData(void* ptr, size_t size, size_t nmemb, void* stream);
};
Expand Down

0 comments on commit 69ee505

Please sign in to comment.