From 69ee50557ce34ac9174381d4a66e187bccc40357 Mon Sep 17 00:00:00 2001 From: "hs.zhang" <22708345+cangfengzhs@users.noreply.github.com> Date: Sun, 29 Jan 2023 15:14:06 +0800 Subject: [PATCH] fix https (#5283) --- src/common/http/HttpClient.cpp | 8 ++++++++ src/common/http/HttpClient.h | 1 + 2 files changed, 9 insertions(+) diff --git a/src/common/http/HttpClient.cpp b/src/common/http/HttpClient.cpp index 3ef01d93619..c3ab96ad0bd 100644 --- a/src/common/http/HttpClient.cpp +++ b/src/common/http/HttpClient.cpp @@ -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()) { @@ -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; diff --git a/src/common/http/HttpClient.h b/src/common/http/HttpClient.h index 9c041fcc012..5eebeb52b27 100644 --- a/src/common/http/HttpClient.h +++ b/src/common/http/HttpClient.h @@ -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); };