Add server cert option
This commit is contained in:
@ -140,6 +140,7 @@ bool AsyncHttpRequest::taskRunning() const
|
|||||||
|
|
||||||
std::expected<void, std::string> AsyncHttpRequest::createClient(std::string_view url, esp_http_client_method_t method,
|
std::expected<void, std::string> AsyncHttpRequest::createClient(std::string_view url, esp_http_client_method_t method,
|
||||||
int timeout_ms,
|
int timeout_ms,
|
||||||
|
std::string_view serverCert,
|
||||||
const std::optional<cpputils::ClientAuth> &clientAuth)
|
const std::optional<cpputils::ClientAuth> &clientAuth)
|
||||||
{
|
{
|
||||||
if (m_client)
|
if (m_client)
|
||||||
@ -160,6 +161,12 @@ std::expected<void, std::string> AsyncHttpRequest::createClient(std::string_view
|
|||||||
.is_async = true,
|
.is_async = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!serverCert.empty())
|
||||||
|
{
|
||||||
|
config.cert_pem = serverCert.data();
|
||||||
|
config.cert_len = serverCert.size();
|
||||||
|
}
|
||||||
|
|
||||||
if (clientAuth)
|
if (clientAuth)
|
||||||
{
|
{
|
||||||
config.client_key_pem = clientAuth->clientKey.data();
|
config.client_key_pem = clientAuth->clientKey.data();
|
||||||
@ -208,6 +215,7 @@ std::expected<void, std::string> AsyncHttpRequest::start(std::string_view url,
|
|||||||
esp_http_client_method_t method,
|
esp_http_client_method_t method,
|
||||||
const std::map<std::string, std::string> &requestHeaders,
|
const std::map<std::string, std::string> &requestHeaders,
|
||||||
std::string &&requestBody, int timeout_ms,
|
std::string &&requestBody, int timeout_ms,
|
||||||
|
std::string_view serverCert,
|
||||||
const std::optional<cpputils::ClientAuth> &clientAuth)
|
const std::optional<cpputils::ClientAuth> &clientAuth)
|
||||||
{
|
{
|
||||||
if (!m_taskHandle)
|
if (!m_taskHandle)
|
||||||
@ -229,7 +237,7 @@ std::expected<void, std::string> AsyncHttpRequest::start(std::string_view url,
|
|||||||
m_client = {};
|
m_client = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto result = createClient(url, method, timeout_ms, clientAuth); !result)
|
if (auto result = createClient(url, method, timeout_ms, serverCert, clientAuth); !result)
|
||||||
return std::unexpected(std::move(result).error());
|
return std::unexpected(std::move(result).error());
|
||||||
|
|
||||||
m_requestBody = std::move(requestBody);
|
m_requestBody = std::move(requestBody);
|
||||||
|
@ -31,6 +31,7 @@ public:
|
|||||||
std::expected<void, std::string> createClient(std::string_view url,
|
std::expected<void, std::string> createClient(std::string_view url,
|
||||||
esp_http_client_method_t method = HTTP_METHOD_GET,
|
esp_http_client_method_t method = HTTP_METHOD_GET,
|
||||||
int timeout_ms = 0,
|
int timeout_ms = 0,
|
||||||
|
std::string_view serverCert = {},
|
||||||
const std::optional<cpputils::ClientAuth> &clientAuth = {});
|
const std::optional<cpputils::ClientAuth> &clientAuth = {});
|
||||||
std::expected<void, std::string> deleteClient();
|
std::expected<void, std::string> deleteClient();
|
||||||
bool hasClient() const;
|
bool hasClient() const;
|
||||||
@ -39,6 +40,7 @@ public:
|
|||||||
esp_http_client_method_t method = HTTP_METHOD_GET,
|
esp_http_client_method_t method = HTTP_METHOD_GET,
|
||||||
const std::map<std::string, std::string> &requestHeaders = {},
|
const std::map<std::string, std::string> &requestHeaders = {},
|
||||||
std::string &&requestBody = {}, int timeout_ms = 0,
|
std::string &&requestBody = {}, int timeout_ms = 0,
|
||||||
|
std::string_view serverCert = {},
|
||||||
const std::optional<cpputils::ClientAuth> &clientAuth = {});
|
const std::optional<cpputils::ClientAuth> &clientAuth = {});
|
||||||
std::expected<void, std::string> retry(std::optional<std::string_view> url = std::nullopt,
|
std::expected<void, std::string> retry(std::optional<std::string_view> url = std::nullopt,
|
||||||
std::optional<esp_http_client_method_t> method = std::nullopt,
|
std::optional<esp_http_client_method_t> method = std::nullopt,
|
||||||
|
Reference in New Issue
Block a user