A minimal HTTP/1.1 server written in C++17 using POSIX sockets. It is intended for learning and experimentation, not production traffic.
- Linux or another POSIX-compatible operating system
- CMake 3.20 or newer
- A C++17-compatible compiler
From the repository root:
cmake -S . -B build
cmake --build buildThe executable is written to build/http_server.
./build/http_serverThe server listens on TCP port 8080 on all local interfaces. In another terminal, send a request with:
curl http://127.0.0.1:8080/The response body is:
OK
Stop the server with Ctrl+C.
- Accepts TCP connections sequentially.
- Reads up to 2,047 bytes from each client request.
- Applies a five-second receive and send timeout.
- Returns
HTTP/1.1 200 OKfor any request that can be read. - Uses a listen backlog of 5 and enables
SO_REUSEADDR.
This implementation does not parse HTTP methods, paths, headers, or request bodies. It does not provide routing, TLS, persistent connections, graceful shutdown, configuration, or production-level error handling.
.
├── include/socket.hpp # RAII wrapper for a file descriptor
├── src/http-server.cpp # Server and request handling
├── CMakeLists.txt # Build configuration
└── LICENSE # MIT License
This project is licensed under the MIT License.