How stegvdm/simple-web-server works
Project type and purpose
• This is a C++ header-only library (with small .cpp example files) providing both HTTP/HTTPS client and server functionality.
• It wraps Asio (Boost.Asio or standalone) for async I/O and OpenSSL for TLS, exposing a simple REST-style interface for C++ applications.
File structure
• Top level:
• CMakeLists.txt, .clang-format, .travis.yml – build and CI config
• *.hpp – core headers: server_http, server_https, client_http, client_https, crypto, status_code, utility
• http_examples.cpp, https_examples.cpp – sample applications
• /web – static HTML for example servers
• /tests – unit tests for crypto, I/O, parsing, status codes
• Patterns: header-only API, examples & tests separated, CMake driving build, Travis CI integration.
Key README insights
• Asynchronous, multithreaded, platform-independent
• Supports HTTP/1.1 persistent connections and chunked transfers
• User defines REST resources via regex + callbacks
• Dependencies: Asio, Boost (for examples), OpenSSL (for HTTPS)
Main components
a. Library API layer
– ServerHTTP module
– ServerHTTPS module (builds on ServerHTTP + Crypto)
– ClientHTTP module
– ClientHTTPS module (builds on ClientHTTP + Crypto)
– Utility & StatusCode modules
b. Underlying I/O and crypto
– Asio (Boost.Asio or standalone)
– OpenSSL for TLS handshake, encryption/decryption
c. Application layer
– Example applications (http_examples, https_examples)
– User’s C++ code invoking library
d. External systems
– Web browser or external HTTP client
– Network (“TCP/IP stack”)
Relationships and interactions
• On the Server side:
1. Asio accepts TCP connections on a port
2. (HTTPS) OpenSSL handshake via Crypto module
3. Incoming HTTP message parsed (Utility + StatusCode)
4. Dispatcher matches regex paths → user callback
5. Callback processes request, builds response
6. Response sent back over Asio socket
7. Thread pool used to handle requests concurrently
• On the Client side:
1. User code calls ClientHTTP/ClientHTTPS to send request
2. Asio establishes TCP connection
3. (HTTPS) TLS handshake via OpenSSL
4. HTTP request serialized and sent
5. Response parsed by Utility + StatusCode
6. Control returned to user callback/future
Architectural patterns and design principles
• Layered architecture: Application → Library API → Transport (Asio) → OS
• Separation of concerns: HTTP vs HTTPS vs Crypto vs Utility
• Dependency inversion: user code passes callbacks, library controls threading
• Header-only design maximizes portability and ease of integration
Detailed element checklist
• Labels for each module and external dependency
• Call out the regex-based routing mechanism in the Server layer
• Optional TLS layer in HTTPS path