Skip to content
Yokio9Public

About

HTTP/1.1 web server written in C++ 98

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

🌐 Webserv - High-Performance HTTP Server

C++ Architecture License

📖 About The Project

Webserv is a fully functional HTTP/1.1 web server written in C++ 98. It is designed to be non-blocking and event-driven, utilizing epoll for I/O multiplexing to handle multiple client connections simultaneously without the overhead of threads.

This project was built to understand the intricacies of the HTTP protocol, socket programming, and low-level server architecture. It mimics the behavior of industry-standard servers like NGINX.


✨ Key Features

Core Architecture

  • Non-Blocking I/O: Uses a single-threaded event loop (epoll) to manage connections efficiently.
  • State Machine Parsing: Robust request parsing that handles partial data and keeps connections alive.
  • Multiplexing: simultaneous handling of read/write events across multiple sockets.

HTTP Capabilities

  • Methods: Full support for GET, POST, and DELETE.
  • Static File Serving: Serves HTML, CSS, JS, images, and large binary files.
  • File Uploads: Handles multipart/form-data and chunked transfer encoding for large file uploads.
  • Directory Listing: Auto-generates HTML directory listings when autoindex is enabled.
  • Redirections: Supports HTTP 3xx redirections.
  • Session Management: Cookies and Session ID support (if implemented).

Configuration

  • Nginx-style Config: Custom configuration parser supporting:
    • Multiple Server Blocks (Virtual Hosting).
    • Port & Host binding.
    • Custom Error Pages (404, 500, etc.).
    • Client Body Size Limits.
    • Route-specific rules (limit_except, root, return, cgi_pass).

🛠️ Architecture Overview

The server follows a React pattern architecture:

  1. Parsing Phase: The configuration file is tokenized and parsed into a virtual server hierarchy.
  2. Setup Phase: Sockets are created, bound to ports, and set to non-blocking mode.
  3. Event Loop: The main loop waits for events via epoll_wait.
    • New Connections: Accepted and added to the monitored set.
    • Read Events: Data is read into a buffer and passed to the HTTP Parser.
    • Write Events: Responses are constructed and sent back in non-blocking chunks.

⚙️ Configuration Syntax

The configuration file uses a block-based syntax similar to NGINX:

server {
    listen 8080;
    server_name localhost;
    root ./www;
    client_max_body_size 1000000; # 1MB Limit

    error_page 404 /errors/404.html;

    location / {
        limit_except GET POST;
        autoindex on;
    }

    location /uploads {
        limit_except GET POST DELETE;
        root ./www/uploads;
        upload_store ./www/uploads;
    }

    location /old-page {
        return 301 [https://google.com](https://google.com);
    }

    location *.php {
        cgi_pass /usr/bin/php-cgi;
    }
}

🧪 Testing

We have included comprehensive shell scripts to stress-test the server's capabilities:

test_get.sh: Validates file serving, 404 handling, and autoindexing.

test_post.sh: Tests multipart uploads, large payloads (413), and chunked encoding.

test_delete.sh: Verifies resource deletion and permission handling.

test_stress.sh: Simulates high load and boundary conditions.

Run a test suite:

chmod +x tests/test_post.sh
./tests/test_post.sh

📸 Dashboard

The project includes a built-in Control Panel (index.html) to interact with the server visually:

Real-time File Uploads.

Gallery View.

One-click File Deletion.

Animation Demos (Canvas API).

👥 Authors

Mouaffak Mehdi - Core Architecture, Parsing, Routing

Faure Lucien - CGI Implementation, Signals, Event Loop

Matayi Dianka - Config Parsing, CGI Setup, Refactoring

🤝 Acknowledgements

Inspired by NGINX.

Built as part of the 42 Curriculum.

About

HTTP/1.1 web server written in C++ 98

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages