An open API service indexing awesome lists of open source software.

https://github.com/jos-felipe/webserv

This project is here to make you write your own HTTP server. You will be able to test it with a real browser. HTTP is one of the most used protocol on internet. Knowing its arcane will be useful, even if you won't be working on a website.
https://github.com/jos-felipe/webserv

network network-and-system-administration object-oriented-programming rigor unix

Last synced: 6 months ago
JSON representation

This project is here to make you write your own HTTP server. You will be able to test it with a real browser. HTTP is one of the most used protocol on internet. Knowing its arcane will be useful, even if you won't be working on a website.

Awesome Lists containing this project

README

          

# WebServ - HTTP Server Implementation


Language
C++ Standard

## ๐Ÿ“– Overview
WebServ is a lightweight HTTP server implementation in C++98. This project is developed to understand the internals of HTTP protocol and web servers, providing hands-on experience with network programming, concurrent connections handling, and HTTP protocol implementation.

> _"This is when you finally understand why a URL starts with HTTP"_

## โœจ Features
- **Fully compliant with HTTP/1.1** protocol specifications
- **Non-blocking I/O operations** using poll/select/epoll/kqueue
- **Multiple virtual servers** support with different configurations
- **Method support**: GET, POST, DELETE
- **Static file serving** with directory listings
- **CGI support** for dynamic content
- **File uploads** handling
- **Error pages** customization
- **Redirections** configuration
- **Client body size limit** configuration

## ๐Ÿงฐ Requirements
- C++ compiler with C++98 support
- Make build system
- UNIX/Linux environment (or MacOS)
- No external libraries (standard library only)

## ๐Ÿ—๏ธ Project Structure
```
webserv/
โ”œโ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ config/ # Configuration parsing
โ”‚ โ”œโ”€โ”€ http/ # HTTP protocol handling
โ”‚ โ”œโ”€โ”€ socket/ # Socket operations
โ”‚ โ”œโ”€โ”€ server/ # Main server implementation
โ”‚ โ”œโ”€โ”€ cgi/ # CGI implementation
โ”‚ โ”œโ”€โ”€ utils/ # Utility functions and classes
โ”‚ โ””โ”€โ”€ main.cpp # Entry point
โ”œโ”€โ”€ include/ # Header files
โ”œโ”€โ”€ conf/ # Configuration examples
โ”œโ”€โ”€ www/ # Web content examples
โ”œโ”€โ”€ tests/ # Test scripts and files
โ”œโ”€โ”€ Makefile # Build script
โ””โ”€โ”€ README.md # This file
```

## ๐Ÿš€ Building and Running
```bash
# Clone the repository
git clone https://github.com/jos-felipe/webserv.git
cd webserv

# Build the project
make

# Run with default configuration
./webserv

# Run with custom configuration
./webserv conf/custom.conf
```

## โš™๏ธ Configuration File
The server uses a configuration file inspired by NGINX to set up different server instances and routes. Here's a basic example:

```
# Simple server configuration
server {
listen 8080;
server_name example.com;
root /var/www/html;

# Default error pages
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;

# Client body size limit (in bytes)
client_max_body_size 10M;

# Route configuration
location / {
# Accepted HTTP methods
method GET POST;

# Directory listing
autoindex on;

# Default file for directories
index index.html;
}

# CGI configuration
location ~ \.php$ {
method GET POST;
cgi_pass /usr/bin/php-cgi;
}

# Redirection example
location /old {
return 301 /new;
}

# Upload configuration
location /upload {
method POST;
upload_store /tmp/uploads;
}
}
```

## ๐Ÿ“‹ Development Progress
- [x] Project setup and repository initialization
- [x] Configuration file parsing
- [x] Socket management and non-blocking I/O
- [x] HTTP request parsing
- [x] HTTP response generation
- [x] Static file serving
- [x] Directory listing
- [x] Error handling
- [x] CGI implementation
- [x] File upload handling
- [x] Testing and documentation

## ๐Ÿงช Testing
The server can be tested using:
- Web browsers (Chrome, Firefox, Safari, etc.)
- Command-line tools (curl, wget)
- Testing scripts (Python, Bash)
- Telnet for raw HTTP request testing
- External tools like Apache Bench for stress testing

## ๐Ÿ‘ฅ Contributors
- [jos-felipe](https://github.com/jos-felipe)
- [Adedayo-Sanni](https://github.com/Adedayo-Sanni)
- [Thiagosdcavalcante](https://github.com/Thiagosdcavalcante)

## ๐Ÿ“„ License
This project is part of the School 42 curriculum.