Preparations for client auth
This commit is contained in:
@@ -140,7 +140,8 @@ bool AsyncHttpRequest::taskRunning() const
|
||||
}
|
||||
|
||||
std::expected<void, std::string> AsyncHttpRequest::createClient(std::string_view url, esp_http_client_method_t method,
|
||||
int timeout_ms)
|
||||
int timeout_ms,
|
||||
const std::optional<cpputils::ClientAuth> &clientAuth)
|
||||
{
|
||||
if (m_client)
|
||||
{
|
||||
@@ -197,7 +198,8 @@ bool AsyncHttpRequest::hasClient() const
|
||||
std::expected<void, std::string> AsyncHttpRequest::start(std::string_view url,
|
||||
esp_http_client_method_t method,
|
||||
const std::map<std::string, std::string> &requestHeaders,
|
||||
std::string_view requestBody, int timeout_ms)
|
||||
std::string_view requestBody, int timeout_ms,
|
||||
const std::optional<cpputils::ClientAuth> &clientAuth)
|
||||
{
|
||||
if (!m_taskHandle)
|
||||
{
|
||||
@@ -218,7 +220,7 @@ std::expected<void, std::string> AsyncHttpRequest::start(std::string_view url,
|
||||
m_client = {};
|
||||
}
|
||||
|
||||
if (auto result = createClient(url, method, timeout_ms); !result)
|
||||
if (auto result = createClient(url, method, timeout_ms, clientAuth); !result)
|
||||
return std::unexpected(std::move(result).error());
|
||||
|
||||
for (auto iter = std::cbegin(requestHeaders); iter != std::cend(requestHeaders); iter++)
|
||||
@@ -262,11 +264,8 @@ std::expected<void, std::string> AsyncHttpRequest::start(std::string_view url,
|
||||
std::expected<void, std::string> AsyncHttpRequest::retry(std::optional<std::string_view> url,
|
||||
std::optional<esp_http_client_method_t> method,
|
||||
const std::map<std::string, std::string> &requestHeaders,
|
||||
std::string_view requestBody
|
||||
#ifndef OLD_IDF
|
||||
, std::optional<int> timeout_ms
|
||||
#endif
|
||||
)
|
||||
std::string_view requestBody, std::optional<int> timeout_ms,
|
||||
const std::optional<cpputils::ClientAuth> &clientAuth)
|
||||
{
|
||||
if (!m_taskHandle)
|
||||
{
|
||||
@@ -304,7 +303,6 @@ std::expected<void, std::string> AsyncHttpRequest::retry(std::optional<std::stri
|
||||
return std::unexpected(std::move(msg));
|
||||
}
|
||||
|
||||
#ifndef OLD_IDF
|
||||
if (timeout_ms)
|
||||
if (const auto result = m_client.set_timeout_ms(*timeout_ms); result != ESP_OK)
|
||||
{
|
||||
@@ -312,7 +310,6 @@ std::expected<void, std::string> AsyncHttpRequest::retry(std::optional<std::stri
|
||||
ESP_LOGW(TAG, "%.*s", msg.size(), msg.data());
|
||||
return std::unexpected(std::move(msg));
|
||||
}
|
||||
#endif
|
||||
|
||||
for (auto iter = std::cbegin(requestHeaders); iter != std::cend(requestHeaders); iter++)
|
||||
if (const auto result = m_client.set_header(iter->first, iter->second); result != ESP_OK)
|
||||
|
@@ -12,10 +12,11 @@
|
||||
#include <freertos/task.h>
|
||||
#include <esp_err.h>
|
||||
|
||||
// local includes
|
||||
#include "wrappers/http_client.h"
|
||||
#include "wrappers/event_group.h"
|
||||
#include "taskutils.h"
|
||||
// 3rdparty lib includes
|
||||
#include <wrappers/http_client.h>
|
||||
#include <wrappers/event_group.h>
|
||||
#include <taskutils.h>
|
||||
#include <clientauth.h>
|
||||
|
||||
class AsyncHttpRequest
|
||||
{
|
||||
@@ -29,22 +30,21 @@ public:
|
||||
|
||||
std::expected<void, std::string> createClient(std::string_view url,
|
||||
esp_http_client_method_t method = HTTP_METHOD_GET,
|
||||
int timeout_ms = 0);
|
||||
int timeout_ms = 0,
|
||||
const std::optional<cpputils::ClientAuth> &clientAuth = {});
|
||||
std::expected<void, std::string> deleteClient();
|
||||
bool hasClient() const;
|
||||
|
||||
std::expected<void, std::string> start(std::string_view url,
|
||||
esp_http_client_method_t method = HTTP_METHOD_GET,
|
||||
const std::map<std::string, std::string> &requestHeaders = {},
|
||||
std::string_view requestBody = {}, int timeout_ms = 0);
|
||||
std::string_view requestBody = {}, int timeout_ms = 0,
|
||||
const std::optional<cpputils::ClientAuth> &clientAuth = {});
|
||||
std::expected<void, std::string> retry(std::optional<std::string_view> url = std::nullopt,
|
||||
std::optional<esp_http_client_method_t> method = std::nullopt,
|
||||
const std::map<std::string, std::string> &requestHeaders = {},
|
||||
std::string_view requestBody = {}
|
||||
#ifndef OLD_IDF
|
||||
,std::optional<int> timeout_ms = {}
|
||||
#endif
|
||||
);
|
||||
std::string_view requestBody = {}, std::optional<int> timeout_ms = {},
|
||||
const std::optional<cpputils::ClientAuth> &clientAuth = {});
|
||||
std::expected<void, std::string> abort();
|
||||
|
||||
bool inProgress() const;
|
||||
|
Reference in New Issue
Block a user