Overview
Webserv is an HTTP/1.1 web server written in modern C++20 that handles multiple
concurrent connections using an epoll-based non-blocking event loop. It serves
static files, executes CGI scripts, and supports virtual host routing — all
configured via an NGINX-style .conf file.
A 42/Hive Helsinki team project built from scratch: no Boost, no Asio, just raw POSIX sockets, epoll, and fork/exec. It passes concurrent load tests and handles keep-alive connections with a 60-second idle timeout.
Key Features
- epoll event loop with non-blocking sockets (
recv/send+MSG_DONTWAIT) - HTTP/1.1 GET, POST, DELETE methods with proper status codes and headers
- Virtual hosts — server-name matching for host-based routing
- CGI execution (Python, PHP, shell) via fork/exec with pipe-based I/O
- Static file serving with MIME detection and autoindex directory listing
- File uploads via multipart/form-data with configurable size limits
- Path canonicalisation and request-size limits to prevent directory traversal
- Custom error pages per status code
Tech Stack
My Role
This was a three-person project. I was responsible for the networking core —
the WebServer and Server classes that manage the epoll
event loop, socket lifecycle (bind, listen, accept), and connection state across
clients. I also drove integration and load testing across the different modules
to verify correctness under concurrent connections.
Challenges & Learnings
The hardest part of my side was managing the full socket lifecycle correctly under
concurrent load — handling partial reads and writes on non-blocking sockets,
detecting stale connections, and ensuring the epoll event loop never missed or
double-processed events. Getting EPOLLIN, EPOLLOUT, and
EPOLLHUP transitions right for each connection state took significant
iteration.
Beyond my own area, collaborating closely on the full project gave me a solid
understanding of the HTTP/1.1 protocol — how requests and responses are structured,
the role of headers like Content-Length and Transfer-Encoding,
keep-alive semantics, and how CGI bridges the gap between the web and arbitrary
processes. It was the project that made HTTP click as more than just a black box.