Skip to content

ipersids/webserv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Webserv

Introduction

A lightweight, HTTP/1.1 compliant web server built in C++17 for educational purposes as part of the 42 school curriculum.

Table of Contents

Features

  • HTTP/1.1 Protocol: RFC 9110/9112 compliant
  • HTTP Methods: GET, POST, DELETE support
  • Static File Serving: HTML, CSS, JS, images, etc.
  • Directory Listings: Automatic index generation
  • File Uploads: Multipart form data handling
  • Custom Error Pages: With fallback defaults
  • Configuration System: Nginx-style config parsing
  • Virtual Hosts: Multiple server support
  • Location Blocks: Routing with method restrictions
  • Chunked Transfer: Request body support
  • Connection Management: Keep-alive and timeout handling
  • Event-Driven I/O: Epoll-based architecture
  • Security: Path traversal protection
  • Logging: Basic request/error logging
  • CGI Support: Dynamic script execution

Project structure

webserv/
├── includes/          # Header files
│   └── *.hpp
├── srcs/              # Source files
│   ├── Config/        # Configuration system
│   ├── main.cpp       # Server entry point
│   └── *.cpp
├── docs/              # Static web content
│   └── fusion_web/    # Demo website
├── tests/             # Unit tests
└── Makefile           # Build system

Demo website structure

docs/fusion_web/
├── index.html          # Main landing page
├── style.css           # Shared stylesheet
├── tours/              # Static content example
├── uploads/            # File upload destination
├── cgi-bin/            # CGI scripts
│   ├── time.py         # Python CGI example
│   └── hello.py        # Simple CGI demo
└── error_pages/        # Custom error pages
    └── 404.html

Quick start

Prerequisites

  • C++17 compatible compiler.
  • Make build system.
  • Linux/Unix environment.

Building

# Clone the repository
git clone <repository-url>
cd webserv

# Build the server
make

# Build with tests (optional)
make test-unit

Running

# Start server with default configuration
./webserv

# Start server with config file
./webserv [path/to-config-file.conf]

# View logs
tail -f logs/webserv.log

# Test manually
curl http://localhost:8002/
curl -X POST -F "[email protected]" http://localhost:8002/uploads/

Configuration

Basic server block:

server {
    listen 8002;
    server_name localhost;
    root docs/fusion_web/;
    index index.html;
    error_page 404 error_pages/404.html;

    location / {
        allow_methods GET POST DELETE;
    }

    location /uploads {
        allow_methods GET POST;
        autoindex on;
    }

    location /cgi-bin {
        allow_methods GET POST;
        cgi_path /usr/bin/python3 /bin/bash;
        cgi_ext .py .sh;
    }
}

Configuration directives Server directives:

  • listen: Port number to bind to
  • server_name: Virtual host names
  • host: IP address
  • root: Document root directory
  • index: Default file to serve
  • error_page: Custom error page mappings

Location directives:

  • allow_methods: Permitted HTTP methods
  • autoindex: Enable/disable directory listings
  • return: HTTP redirect configuration
  • cgi_path: CGI interpreter paths
  • cgi_ext: CGI file extensions

Developed by

About

A lightweight, HTTP/1.1 compliant web server built in C++17

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •