idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
ssl_server.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Chris Leishman
3
4#pragma once
5
27#include <idfxx/cpu>
28#include <idfxx/error>
29#include <idfxx/http/server>
30
31#include <chrono>
32#include <cstdint>
33#include <functional>
34#include <optional>
35#include <string>
36
37namespace idfxx::http {
38
53class ssl_server : public server {
54public:
65 struct config {
66 // Task
68 size_t stack_size = 10240;
69 std::optional<core_id> core_affinity = std::nullopt;
70
71 // Network
75
76 // Limits
80 size_t max_req_hdr_len = 0;
81 size_t max_uri_len = 0;
82
83 // Timeouts
84 std::chrono::seconds recv_wait_timeout{5};
85 std::chrono::seconds send_wait_timeout{5};
86
87 // LRU
88 bool lru_purge_enable = true;
89
90 // SO_LINGER
91 bool enable_so_linger = false;
92 std::chrono::seconds linger_timeout{0};
93
94 // Keep-alive
95 bool keep_alive_enable = false;
96 std::chrono::seconds keep_alive_idle{0};
97 std::chrono::seconds keep_alive_interval{0};
99
100 // URI matching
101 bool wildcard_uri_match = false;
102
103 // Session callbacks
105 std::move_only_function<result<void>(int) const> on_session_open = {};
107 std::move_only_function<void(int) const> on_session_close = {};
108
109 // TLS configuration
110 std::string server_cert = {};
111 std::string private_key = {};
112 std::string client_ca_cert = {};
113 bool use_ecdsa_peripheral = false;
115 bool session_tickets = false;
116 bool use_secure_element = false;
117 std::chrono::milliseconds handshake_timeout{0};
118 };
119
120#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
143#endif
144
152
153 ~ssl_server() override = default;
154
155 ssl_server(const ssl_server&) = delete;
156 ssl_server& operator=(const ssl_server&) = delete;
157
160
163
164private:
167 httpd_handle_t handle,
169 std::move_only_function<result<void>(int) const> on_session_open,
170 std::move_only_function<void(int) const> on_session_close
171 );
173};
174
175} // namespace idfxx::http
176
// end of idfxx_https_server
HTTP server with URI handler registration and RAII lifecycle.
Definition server.hpp:478
HTTPS server with TLS support.
~ssl_server() override=default
ssl_server & operator=(const ssl_server &)=delete
ssl_server(config cfg)
Creates and starts an HTTPS server.
ssl_server(ssl_server &&) noexcept=default
Move constructor.
ssl_server(const ssl_server &)=delete
static result< ssl_server > make(config cfg)
Creates and starts an HTTPS server.
Type-safe wrapper for FreeRTOS task priority values.
Definition cpu.hpp:84
void * httpd_handle_t
Definition server.hpp:37
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Definition error.hpp:120
HTTPS server configuration.
size_t stack_size
Stack size for the server task (10KB)
std::move_only_function< void(int) const > on_session_close
Called when a session is closed.
uint16_t ctrl_port
Control port for server commands.
std::chrono::milliseconds handshake_timeout
TLS handshake timeout (0 = default 10s)
size_t max_uri_len
Maximum URI length (0 = Kconfig default)
std::chrono::seconds keep_alive_idle
Keep-alive idle time.
std::chrono::seconds keep_alive_interval
Keep-alive probe interval.
uint16_t max_resp_headers
Maximum additional response headers.
std::chrono::seconds linger_timeout
Linger timeout.
std::chrono::seconds send_wait_timeout
Send timeout.
bool lru_purge_enable
Purge least-recently-used connections when full.
std::chrono::seconds recv_wait_timeout
Receive timeout.
bool use_ecdsa_peripheral
Use ECDSA peripheral for key operations.
uint16_t server_port
HTTPS listening port.
size_t max_req_hdr_len
Maximum request header length (0 = Kconfig default)
uint16_t backlog_conn
Maximum backlog connections.
bool use_secure_element
Use secure element for key storage.
std::string private_key
Server private key (PEM format)
uint16_t max_uri_handlers
Maximum registered URI handlers.
std::optional< core_id > core_affinity
Core pin (nullopt = any core)
bool session_tickets
Enable TLS session tickets.
bool wildcard_uri_match
Enable wildcard URI matching.
std::string client_ca_cert
CA cert for client verification (optional, PEM format)
task_priority priority
Priority of the server task.
std::move_only_function< result< void >(int) const > on_session_open
Called when a new session is opened.
bool keep_alive_enable
Enable TCP keep-alive.
std::string server_cert
Server certificate (PEM format)
bool enable_so_linger
Enable SO_LINGER on sockets.
uint16_t max_open_sockets
Maximum concurrent client connections.
uint8_t ecdsa_key_efuse_blk
eFuse block number for ECDSA key
int keep_alive_count
Keep-alive probe count.