Skip to content

A fully asynchronous HTTP/1.1 server built from scratch in C++98. Zero dependencies. epoll-powered. Production-grade.

Notifications You must be signed in to change notification settings

ITAXBOX/Webserv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

139 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

WebServ - Cache Me If You Can

Outstanding Project โ€ข 125/100 @ 42 Beirut | epoll-powered HTTP/1.1 server in C++98

Made with C++98 HTTP/1.1 Compliant epoll Powered Grade

WebServ Homepage

Zero dependencies โ€ข Pure C++98 โ€ข Production-grade


โœจ What We Built

A fully asynchronous HTTP/1.1 server that doesn't just work-it shines. From the reactor-pattern event loop to the stunning web interface, every detail was crafted with precision.

๐Ÿš€ Quick Start

# Build the server
make

# Launch it
./webserv conf/default.conf

# Open your browser
http://localhost:8080

That's it. Three commands. One beautiful interface.


๐ŸŽจ The Experience

We didn't just build a server. We built an experience. A modern, interactive web interface with aurora gradients, glassmorphism effects, and real-time testing capabilities.

Interactive Testing Console

Test all HTTP methods with live console feedback

What Makes It Special

  • ๐ŸŒŒ Aurora Background Effects - Animated gradient meshes that breathe life into the page
  • ๐Ÿ’Ž Glassmorphism UI - Frosted glass effects with blur and transparency
  • โœจ Animated Shimmer Text - The title and team name glow and shimmer with gradient animations
  • ๐ŸŽฏ Real-Time Testing - Execute HTTP requests and see responses instantly
  • ๐Ÿ”ฅ Interactive Particles - Mouse-reactive particle system with connection lines
  • ๐Ÿ“ฑ Fully Responsive - Looks stunning on any device

โšก Architecture: Where Beauty Meets Performance

System Flow Chart

Event-driven architecture with epoll at its core

The Reactor Pattern in Action

Our event loop is a symphony of O(1) efficiency:

  1. epoll_wait() monitors all file descriptors in a single syscall
  2. ConnectionManager dispatches events to the right handlers
  3. Handlers process data without ever blocking
  4. Rinse and repeat - thousands of connections, zero threads

Why This Matters:

  • select() โ†’ O(n) - scans every descriptor
  • poll() โ†’ O(n) - same performance, no limit
  • epoll() โ†’ O(1) - kernel maintains the ready list

We chose speed. We chose epoll.

Architecture Diagram

Visual representation of our reactor-based architecture


๐ŸŽฏ Design Patterns: The Five Pillars

Design Patterns Implementation

Strategy, State, Factory, Observer, Reactor

1. Strategy Pattern - HTTP Method Handlers

Every HTTP method is a pluggable strategy. Want to add PATCH? Write one class. Zero changes to the core.

2. State Pattern - HTTP Parsing

Parsing happens in stages. Each state knows its job. Handles partial reads naturally.

3. Factory Pattern - Response Generation

All responses flow through one factory. Consistency guaranteed.

4. Observer Pattern - Event Notifications

Components subscribe to events. Decoupled. Clean. Maintainable.

5. Reactor Pattern - The Core

The heart of everything. Event detection โ†’ dispatch โ†’ handle. Never block.


๐Ÿ”ฅ CGI: Async All The Way Down

CGI Protocol Flow

Non-blocking CGI execution pipeline

Most servers block on CGI. We don't.

Our CGI pipeline:

  • Fork process (non-blocking)
  • Setup pipes (stdin/stdout/stderr)
  • Register pipes with epoll
  • Stream data asynchronously
  • Parse CGI headers
  • Clean up gracefully

The result? Your server never freezes. Even if a CGI script takes forever.


๐Ÿช Session Management

Session State Management

Cookie-based session flow with server-side storage

Stateful HTTP without the complexity:

  • UUID-based session IDs
  • Automatic cookie injection
  • Server-side key-value storage
  • Concurrent session support
  • Timeout management

๐ŸŽฎ The Frontend: God-Tier Beauty

We didn't settle for "good enough." We went for outstanding.

Features That Make You Go "Wow"

โœจ Hero Section

  • Massive, shimmer-animated title with glint effects
  • Glowing team name with gradient animation
  • Diamond separators and animated badges
  • Breathing particle system with 100+ interactive nodes
  • Multi-layered aurora mesh with floating gradients

๐ŸŽจ Visual Effects

  • 4 animated glow spots (gold, amber, rose, violet)
  • Film grain noise texture overlay
  • Glass morphism on terminal and cards
  • Color-blended particle connection lines
  • Mouse-reactive particle glow-up effect
  • Radial cursor light

๐Ÿš€ Interactive Elements

  • Tab-based HTTP method testing
  • Real-time console output
  • CGI script gallery with one-click execution
  • Session/cookie inspector
  • Hover animations on all cards
  • Smooth scroll reveal animations

๐Ÿ“Š What We Support

Feature Status Notes
GET โœ… Static files, directory listing, CGI, query params
POST โœ… Form data, JSON, multipart uploads, CGI input
PUT โœ… Create/update resources, auto-create directories
DELETE โœ… File deletion with safety checks
HEAD โœ… Metadata without body content
Keep-Alive โœ… Persistent connections
Chunked Encoding โœ… Transfer-Encoding: chunked
Sessions โœ… Cookie-based with server storage
MIME Types โœ… Content negotiation
CGI/1.1 โœ… Python, Shell, any executable
Custom Errors โœ… Branded 404/500 pages
Timeouts โœ… Request timeout protection
Security โœ… Path traversal prevention, size limits

๐Ÿ—๏ธ Project Structure

Webserv/
โ”œโ”€โ”€ include/             # Headers organized by layer
โ”‚   โ”œโ”€โ”€ app/             # Request handlers (Strategy pattern)
โ”‚   โ”œโ”€โ”€ config/          # Configuration parser (Builder)
โ”‚   โ”œโ”€โ”€ core/            # Event loop, epoll, connection manager (Reactor)
โ”‚   โ”œโ”€โ”€ http/            # HTTP protocol, parser (State pattern)
โ”‚   โ””โ”€โ”€ utils/           # MIME types, sessions, logging
โ”œโ”€โ”€ src/                 # Implementation files (mirrors include/)
โ”œโ”€โ”€ www/                 # Web root with stunning interface
โ”‚   โ”œโ”€โ”€ index.html       # God-tier homepage
โ”‚   โ”œโ”€โ”€ cgi-bin/         # CGI scripts (Python, Shell)
โ”‚   โ””โ”€โ”€ uploads/         # Upload directory (auto-created)
โ”œโ”€โ”€ conf/                # NGINX-style configurations
โ”œโ”€โ”€ images/              # Screenshots and diagrams
โ””โ”€โ”€ Makefile             # Build system

๐Ÿงช Testing It Out

Via Browser (Recommended)

make && ./webserv conf/default.conf

Then open http://localhost:8080 and explore:

  • Interactive HTTP method testing
  • CGI script gallery
  • Session/cookie inspector
  • Real-time response console

Via Command Line

# GET request
curl http://localhost:8080/

# POST with data
curl -X POST -d "key=value" http://localhost:8080/cgi-bin/post_test.py

# Upload file
curl -X POST -F "file=@myfile.txt" http://localhost:8080/uploads

# PUT resource
curl -X PUT -d "content" http://localhost:8080/uploads/test.txt

# DELETE resource
curl -X DELETE http://localhost:8080/uploads/test.txt

# HEAD metadata
curl -I http://localhost:8080/

# CGI with query
curl "http://localhost:8080/cgi-bin/calculator.py?a=5&b=3&op=add"

๐Ÿ› ๏ธ Makefile Commands

make          # Build the server
make debug    # Build with verbose logging
make clean    # Remove object files
make fclean   # Full cleanup (includes www/uploads)
make re       # Rebuild from scratch

๐ŸŽฏ Why This Project Stands Out

Technical Excellence:

  • Reactor pattern with epoll (O(1) performance)
  • Five design patterns working in harmony
  • Non-blocking I/O throughout the entire stack
  • Zero external dependencies (pure C++98)

Visual Brilliance:

  • Production-quality web interface
  • Aurora gradients and glassmorphism
  • Interactive particle system
  • Animated text effects

Production Ready:

  • Comprehensive error handling
  • Security measures (path traversal, timeouts, size limits)
  • NGINX-style configuration
  • Full HTTP/1.1 compliance

The Result: 125/100 - Outstanding Project @ 42 Beirut


๐Ÿ‘ฅ Team

Cache Me If You Can

  • Ali Itawi
  • Mohamad Al Mohamad
  • Farah El Khatib

Built with precision at 42 Beirut


๐Ÿ™ Acknowledgments

  • 42 School for pushing us to build something exceptional
  • epoll for making asynchronous I/O beautiful
  • NGINX for configuration inspiration
  • The Gang of Four for timeless design patterns

๐Ÿ“œ License

Educational project for 42 School curriculum.


โญ Outstanding Project โญ

When they said "build a web server," we built a masterpiece.

About

A fully asynchronous HTTP/1.1 server built from scratch in C++98. Zero dependencies. epoll-powered. Production-grade.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •