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 structured HttpRequest objects.

  • HTTP Objects (httpserver_impl/http/http_object.h): Defines the fundamental HttpRequest and HttpResponse data 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