Class HttpServerManager

Class Documentation

class HttpServerManager

Manages HTTP/HTTPS server instances with TLS support.

This class abstracts the creation and management of cpp-httplib Server or SSLServer instances based on TLS configuration. It provides a unified interface to get the active server pointer, eliminating code duplication.

Public Functions

explicit HttpServerManager(const TlsConfig &tls_config)

Construct HTTP server manager.

Parameters:

tls_config – TLS configuration (if enabled, creates SSLServer)

Throws:

std::runtime_error – if TLS is requested but SSL server creation fails

~HttpServerManager() = default
HttpServerManager(const HttpServerManager&) = delete
HttpServerManager &operator=(const HttpServerManager&) = delete
HttpServerManager(HttpServerManager&&) = default
HttpServerManager &operator=(HttpServerManager&&) = default
httplib::Server *get_server()

Get pointer to the active server instance.

Note

Returns nullptr if no server was successfully created

Returns:

Pointer to httplib::Server (or SSLServer cast to Server*)

inline bool is_tls_enabled() const

Check if TLS is enabled.

void listen(const std::string &host, int port)

Start listening on the specified host and port.

Parameters:
  • host – Host address to bind to

  • port – Port number to bind to

void stop()

Stop the server if running.

bool is_running() const

Check if server is currently running.