A production-style HTTP/1.1 server written from scratch in C++ using the WinSock2 API.
This project demonstrates low-level networking, HTTP protocol handling, multithreading, configuration management, and structured logging — without using any external frameworks.
-
⚡ TCP server using WinSock2
-
🌐 HTTP/1.1 request parsing (GET)
-
📁 Static file serving (HTML, CSS, JS, images)
-
🧵 Multithreaded architecture (one thread per client)
-
⚙️ INI-based configuration system
-
📝 Thread-safe logging (console + file)
-
🛡️ Security features
- Path traversal protection (
..) - Request size limiting (413)
- Connection limits (503 when overloaded)
- Path traversal protection (
-
⏱️ Socket timeouts (prevents hanging connections)
-
🔌 Graceful shutdown (Ctrl+C)
-
📦 MIME type detection
The server is built with a modular design:
-
Networking layer → WinSock (socket, bind, listen, accept)
-
HTTP layer → request parsing, response building
-
Core system
- Config loader (INI parser)
- Logger (thread-safe)
- File system handler
-
Concurrency model
- One thread per connection
- Atomic counters for active clients
HttpServer-cpp/
│
├── main.cpp # Core server implementation
├── config.ini # Server configuration
├── static/ # Static files (HTML, CSS, JS)
├── logs/ # Log files (auto-created)
├── CMakeLists.txt
└── README.md
The server is fully configurable via config.ini.
[server]
host = 127.0.0.1
port = 8080
www_root = static
max_connections = 20
max_active_clients = 100
buffer_size = 37020
max_request_size = 8192
recv_timeout_ms = 5000
send_timeout_ms = 5000
[logging]
log_to_file = true
log_level = INFO
log_dir = logsMake sure WinSock is linked:
target_link_libraries(HttpServer_cpp ws2_32)Then build:
cmake --build .
./HttpServer_cpp.exe
http://127.0.0.1:8080
GET /index.html HTTP/1.1
Host: 127.0.0.1:8080
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 123
<html>...</html>
| Status | Description |
|---|---|
| 200 | OK |
| 403 | Forbidden (path traversal blocked) |
| 404 | File not found |
| 413 | Request too large |
| 503 | Server overloaded |
Logs include:
- connection events
- requests
- errors
- performance data
Example:
[2026-04-29 14:32:10] [INFO ] Connected: 127.0.0.1
[2026-04-29 14:32:10] [INFO ] Requested: /index.html
[2026-04-29 14:32:10] [INFO ] Serving file (512 bytes)
- Prevents directory traversal attacks (
../) - Limits request size
- Connection throttling
- Socket timeouts (anti-slowloris)
- Windows-only (WinSock)
- No HTTPS (TLS)
- Thread-per-connection model (not scalable for very high load)
- Thread pool instead of detached threads
- HTTP Keep-Alive support
- POST / JSON API handling
- Async I/O (IOCP)
- Linux support (POSIX sockets)
- Reverse proxy mode
- Low-level networking (TCP, sockets)
- HTTP protocol internals
- Multithreading & synchronization
- File I/O and MIME handling
- System-level programming in C++
- Building production-style architecture without frameworks
This project shows the ability to:
- build backend systems from scratch
- understand how the web actually works under the hood
- work with low-level APIs and system programming
⭐ If you like this project, consider starring it!