API Reference¶
HTTPServer API documentation.
Project Structure¶
The project is organized into several key directories:
lib/: Core library source code.lib/include/httpserver: Public umbrella header file.lib/src/httpserver_impl/: Module-specific implementation and headers.
src/: Entry point for the example HTTP server application.public/: Directory containing static assets (HTML, CSS, JS) used by the example server.tests/: Suite of unit tests (GoogleTest) and integration tests (Pytest).
Key Components¶
The following components form the core of the HTTPServer library:
Server (
httpserver_impl/core/server.h): Manages the server lifecycle, socket listening, and connection dispatching.Router (
httpserver_impl/routing/router.h): Maps incoming request paths and methods to application-defined handler functions.HTTP Parser (
httpserver_impl/http/http_parser.h): Parses raw network bytes into structuredHttpRequestobjects.HTTP Objects (
httpserver_impl/http/http_object.h): Defines the fundamentalHttpRequestandHttpResponsedata structures.Response Builder (
httpserver_impl/http/http_response_builder.h): A fluent helper for constructing HTTP responses.Thread Pool (
httpserver_impl/threading/thread_pool.h): Manages a pool of worker threads for handling concurrent requests.Configuration (
httpserver_impl/utils/config.h): Handles runtime server settings, including port, TLS, and performance limits.Connection Guard (
httpserver_impl/core/connection_guard.h): An RAII utility for managing and tracking active client connections.Connection Manager (
httpserver_impl/core/connection_manager.h): Manages active client connections and enforces IP-based rate limiting across the server.Periodic Cleanup (
httpserver_impl/utils/periodic_idle_ip_cleanup.h): A background service for cleaning up inactive client IP records.Port (
httpserver_impl/utils/port.h): A type-safe abstraction for handling network port numbers and representations.Logger (
httpserver_impl/monitoring/logger.h): Provides thread-safe logging for server events and errors.Log Event (
httpserver_impl/monitoring/log_event.h): Represents structured log data with key-value pairs.Log Level (
httpserver_impl/monitoring/log_level.h): Defines severity levels (INFO, WARN, ERROR) for the logging system.Utilities (
httpserver_impl/utils/utils.h): Shared helper functions for URI decoding, MIME-type lookup, and more.Metrics (
httpserver_impl/monitoring/metrics.h): Tracks server-level performance data including active connections, request counts, response statuses, and latency.Event Dispatcher (
httpserver_impl/events/event_dispatcher.h): A central hub for internal server events, allowing components like Metrics to subscribe and react to changes.Umbrella Header (
httpserver): A single header including most common library components.
Detailed API¶
- Config
HTTPServerHTTPServer::ConfigHTTPServer::ServerConfigkPortkRedirectionPortkEnableHttpskCertFilekKeyFilekEnableHttpRedirectionkCleanupIntervalkIdleTimeoutkClientTimeoutSeckMaxRequestDurationSeckRecvBufferSizekMinThreadskMaxThreadskMaxQueueSizekMaxConnectionsPerIpkMaxKeepAliveRequestskMaxTokenskRefillRatekMaxHeaderByteskMaxHeaderCountkMaxTotalHeaderSizekMaxBodyByteskAllowedMethodskAllowedVersionskLogLevelkFileLoggingEnabledkFileLoggingPath
- Connection Guard
- Connection Handler
- Connection Manager
- Event Dispatcher
- Events
- Http Object
- Http Parser
HTTPServerParseStateBodyTypeChunkStateParseResultParseErrorNONEINVALID_REQUEST_LINE_FORMATREQUEST_METHOD_EMPTYREQUEST_METHOD_LOWERCASEUNSUPPORTED_METHODUNSUPPORTED_VERSIONINVALID_HEADER_MISSING_COLONINVALID_HEADER_UNSUPPORTED_CHARACTERHEADER_TOO_LARGEMISSING_HOST_HEADERCONTENT_LENGTH_EMPTYCONTENT_LENGTH_NOT_NUMERICBODY_TOO_LARGEINVALID_CHUNKED_ENCODINGTOO_MANY_HEADERSTOTAL_HEADER_SIZE_TOO_LARGE
HTTPServer::HttpParserHttpParser()parse()hasCompleteRequest()takeRequest()hasError()error()reset()parseRequestLine()parseHeaders()determineBodyFraming()parseBody()parseChunkSize()parseChunkData()parseChunkTrailers()consumeLine()validateRequestLine()validateHeaders()parseQueryParams()urlDecode()d_stated_bodyTyped_chunkStated_errord_requestd_lineBufferd_bodyBytesRemainingd_currentChunkSized_currentChunkReadd_currentHeaderCountd_currentTotalHeaderSize
- Http Response Builder
- Httpserver
- Log Event
- Log Level
- Log Stream
- Logger
- Metrics
HTTPServerHTTPServer::MetricsonEvent()incrementActiveConnection()decrementActiveConnection()incrementTotalRequests()recordResponseStatus()recordBytesReceived()recordBytesSent()recordRequestProcessingTime()snapshot()instance()Metrics()~Metrics()Metrics()operator=()Metrics()operator=()d_activeConnectionsd_totalRequestsd_responses2xxd_responses3xxd_responses4xxd_responses5xxd_totalBytesReceivedd_totalBytesSentd_totalRequestProcessingTimeMs
HTTPServer::MetricsSnapshot
- Periodic Idle Ip Cleanup
- Port
- Route Matchers
- Router
- Server
HTTPServerHTTPServer::ServerServer()Server()Server()operator=()port()start()installSignalHandlers()stop()UniqueSSL_CTXaccept_loop()init_ssl_context()cleanup_ssl_context()dispatch_client()handle_client()handle_client()start_http_redirect()server_fdredirection_server_fdd_runningd_thread_poolssl_ctxd_periodic_idle_ip_cleanup
- Thread Pool
- Unique Fd
- Utils