22#include <idfxx/http/types>
31#include <system_error>
34struct esp_http_client_event;
62 std::span<const uint8_t>
data;
112 std::string url = {};
113 std::string host = {};
115 std::string path = {};
116 std::string query = {};
122 std::string username = {};
123 std::string password = {};
127 std::string cert_pem = {};
128 std::string client_cert_pem = {};
129 std::string client_key_pem = {};
132 std::string user_agent = {};
135 bool disable_auto_redirect =
false;
136 int max_redirection_count = 0;
137 int max_authorization_retries = 0;
141 int buffer_size_tx = 0;
144 bool keep_alive_enable =
false;
145 std::chrono::seconds keep_alive_idle{5};
146 std::chrono::seconds keep_alive_interval{5};
147 int keep_alive_count = 3;
150 bool use_global_ca_store =
false;
151 bool skip_cert_common_name_check =
false;
152 std::string common_name = {};
164 std::move_only_function<
int(
void*)
const> crt_bundle_attach = {};
170#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
207#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
242 void set_header(std::string_view key, std::string_view value);
290 template<
typename Rep,
typename Period>
292 _set_timeout(std::chrono::ceil<std::chrono::milliseconds>(
timeout));
299#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
332#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
535#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
576 std::move_only_function<
void(
const event_data&)
const> on_event,
577 std::move_only_function<
int(
void*)
const> crt_bundle_attach,
579 std::string cert_pem,
580 std::string client_cert_pem,
581 std::string client_key_pem
584 void _set_timeout(std::chrono::milliseconds
timeout);
588 const std::string& cert_pem,
589 const std::string& client_cert_pem,
590 const std::string& client_key_pem
597 std::move_only_function<
int(
void*)
const> _crt_bundle_attach;
598 std::string _post_data;
599 std::string _cert_pem;
600 std::string _client_cert_pem;
601 std::string _client_key_pem;
651struct is_error_code_enum<
idfxx::http::client::errc> : true_type {};
655#include "sdkconfig.h"
656#ifdef CONFIG_IDFXX_STD_FORMAT
663struct formatter<
idfxx::http::event_id> {
664 constexpr auto parse(format_parse_context& ctx) {
return ctx.begin(); }
666 template<
typename FormatContext>
669 return std::copy(s.begin(), s.end(), ctx.out());
Error category for HTTP client errors.
std::string message(int ec) const override final
Returns a human-readable message for the given error code.
const char * name() const noexcept override final
Returns the name of the error category.
HTTP client with blocking and streaming request support.
void delete_header(std::string_view key)
Deletes a request header.
result< void > try_set_url(std::string_view url)
Sets the request URL.
client(client &&) noexcept
Move constructor.
result< size_t > try_read(std::span< char > buf)
Reads response body data into a character buffer.
void perform()
Performs a blocking HTTP request.
void set_url(std::string_view url)
Sets the request URL.
result< size_t > try_write(std::span< const uint8_t > data)
Writes data to the open connection.
void open(size_t write_len=0)
Opens a connection for streaming.
int64_t content_length() const
Returns the response content length.
client(config cfg)
Creates an HTTP client from configuration.
void set_password(std::string_view password)
Sets the password for authentication.
void set_auth_type(enum auth_type type)
Sets the authentication type.
void set_username(std::string_view username)
Sets the username for authentication.
size_t write(std::span< const uint8_t > data)
Writes data to the open connection.
void close()
Closes the connection.
void reset_redirect_counter()
Resets the redirect counter to zero.
result< void > try_perform()
Performs a blocking HTTP request.
result< void > try_set_redirection()
Applies the current redirect URL.
result< void > try_close()
Closes the connection.
size_t read(std::span< char > buf)
Reads response body data into a character buffer.
result< size_t > try_write(std::string_view data)
Writes string data to the open connection.
std::optional< std::string > get_header(std::string_view key) const
Retrieves a response header value.
result< int64_t > try_fetch_headers()
Reads and processes response headers.
static result< client > make(config cfg)
Creates an HTTP client from configuration.
result< void > try_flush_response()
Discards any remaining response data.
void set_method(enum method m)
Sets the HTTP method.
void open(int write_len)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void set_header(std::string_view key, std::string_view value)
Sets a request header.
client & operator=(const client &)=delete
void set_redirection()
Applies the current redirect URL.
client(const client &)=delete
~client()
Destroys the client and releases all resources.
void set_timeout(const std::chrono::duration< Rep, Period > &timeout)
Sets the request timeout.
bool is_chunked_response() const
Checks whether the response uses chunked transfer encoding.
int status_code() const
Returns the HTTP response status code.
void flush_response()
Discards any remaining response data.
void set_post_field(std::string_view data)
Sets the POST request body.
result< void > try_open(int write_len)
This is an overloaded member function, provided for convenience. It differs from the above function o...
result< size_t > try_read(std::span< uint8_t > buf)
Reads response body data.
int64_t fetch_headers()
Reads and processes response headers.
errc
Error codes for HTTP client operations.
@ max_redirect
Maximum number of redirects exceeded.
@ fetch_header
Error reading response headers.
@ connection_closed
Connection closed by remote.
@ write_data
Error writing request data.
@ connecting
Connection in progress (async mode)
@ eagain
Resource temporarily unavailable, try again.
@ connect
Connection to server failed.
@ invalid_transport
Invalid transport type specified.
result< void > try_open(size_t write_len=0)
Opens a connection for streaming.
size_t read(std::span< uint8_t > buf)
Reads response body data.
std::string get_url() const
Retrieves the current effective URL.
size_t write(std::string_view data)
Writes string data to the open connection.
esp_http_client_handle_t idf_handle() const noexcept
Returns the underlying ESP-IDF HTTP client handle.
Concept for types that can be both received and posted as event data.
std::string to_string(core_id c)
Returns a string representation of a CPU core identifier.
struct esp_http_client * esp_http_client_handle_t
method
HTTP request methods.
auth_type
HTTP authentication types.
event_id
HTTP client event identifiers.
@ on_data
Received response body data.
@ on_header
Received a response header.
@ disconnected
Disconnected from the server.
@ on_connected
Connected to the server.
@ headers_sent
All request headers have been sent.
@ on_finish
Finished a complete HTTP session.
@ error
An error occurred during the HTTP operation.
@ redirect
Intercepting a redirect.
std::unexpected< std::error_code > http_client_error(esp_err_t e)
Creates an unexpected error from an ESP-IDF error code, mapping to HTTP client error codes where poss...
std::error_code make_error_code(client::errc e) noexcept
Creates an error code from an idfxx::http::client::errc value.
const client::error_category & http_client_category() noexcept
Returns a reference to the HTTP client error category singleton.
transport
HTTP transport types.
@ unknown
Unknown transport.
T unwrap(result< T > result)
Throws a std::system_error if the result is an error.
@ timeout
Operation timed out.
std::expected< T, std::error_code > result
result type wrapping a value or error code.
HTTP client configuration.
std::string_view header_key
Header name for on_header events.
std::string_view header_value
Header value for on_header events.
std::span< const uint8_t > data
Payload for on_data events.
enum event_id id
Event type.