WebServ is a fully functional HTTP server written in C++98 from scratch. Unlike standard web servers (Apache/Nginx), this project does not use any external network libraries. It interacts directly with the OS kernel using Sockets and Multiplexing.
The goal was to build a robust server capable of handling multiple concurrent connections simultaneously without blocking, using a single thread. It strictly follows the RFC 7230 protocol standards.
| Feature | Implementation Details |
|---|---|
| I/O Multiplexing | Uses select(), poll(), or epoll() to handle non-blocking I/O operations efficiently. |
| HTTP Methods | Full support for GET (Static files), POST (Uploads), and DELETE. |
| CGI Support | Executes external scripts (PHP, Python) via fork() and execve(), piping output back to the client. |
| Robust Parsing | State-machine based parsing for HTTP Headers, Chunked Transfer Encoding, and URI validation. |
| Configuration | Custom .conf file parser inspired by Nginx (Server blocks, Routes, Error pages). |
| Stress Tested | Validated using Siege for concurrency and memory stability (Zero Leaks). |
The server operates on an Event-Driven Architecture:
- Socket Creation: Sets up a listening socket on the specified port.
- Non-Blocking Mode: All file descriptors (FDs) are set to non-blocking.
- The Loop:
- Monitor:
epollwaits for events (Read/Write) on FDs. - Accept: If the Listener has an event, accept new client.
- Read: If a Client FD is readable, parse the raw HTTP request.
- Process: Route the request (Static file or CGI).
- Write: If Client FD is writable, send the built HTTP response.
- Monitor:
// Simplified Event Loop Logic
while (server_is_running) {
int events = epoll_wait(epoll_fd, event_list, MAX_EVENTS, -1);
for (int i = 0; i < events; i++) {
if (event_list[i].data.fd == server_socket)
handle_new_connection();
else if (event_list[i].events & EPOLLIN)
handle_request(event_list[i].data.fd);
else if (event_list[i].events & EPOLLOUT)
send_response(event_list[i].data.fd);
}
}π Installation & Usage Prerequisites C++ Compiler (clang++ / g++)
Make
Building
git clone https://github.com/70rn4d0/WebServer.git
cd WebServer_http
makeRunning
# Run with default config
./webserv first.confTesting (with Siege) To test concurrency and availability:
siege -b -c 100 -t 30S [http://127.0.0.1:8080/](http://127.0.0.1:8080/)