Skip to content

70rn4d0/WebServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation



🌐 About The Project

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.


⚑ Technical Highlights

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).

πŸ—οΈ Architecture: The Event Loop

The server operates on an Event-Driven Architecture:

  1. Socket Creation: Sets up a listening socket on the specified port.
  2. Non-Blocking Mode: All file descriptors (FDs) are set to non-blocking.
  3. The Loop:
    • Monitor: epoll waits 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.
// 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
make

Running

# Run with default config
./webserv first.conf

Testing (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/)

About

HTTP/1.1 Server from scratch.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published