Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/servettonga/cpp_webserv
A lightweight HTTP/1.1 compliant web server supporting static file serving, CGI execution, and virtual hosts.
https://github.com/servettonga/cpp_webserv
cpp cpp98 http http-server nginx websocket
Last synced: 9 days ago
JSON representation
A lightweight HTTP/1.1 compliant web server supporting static file serving, CGI execution, and virtual hosts.
- Host: GitHub
- URL: https://github.com/servettonga/cpp_webserv
- Owner: servettonga
- Created: 2024-10-03T15:06:31.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2025-01-07T23:01:38.000Z (12 days ago)
- Last Synced: 2025-01-08T00:17:55.842Z (11 days ago)
- Topics: cpp, cpp98, http, http-server, nginx, websocket
- Language: C
- Homepage:
- Size: 41.9 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# A HTTP server in C++98
A lightweight HTTP/1.1 compliant web server supporting static file serving, CGI execution, and virtual hosts.
## Features
- **HTTP/1.1 Compliance**
- `GET`, `POST`, `DELETE` methods
- Keep-alive connections
- Status codes per RFC standards- **Core Functionality**
- Static file serving
- Directory listing
- File uploads
- CGI execution
- Virtual host support- **Performance**
- Non-blocking I/O
- Single `select()` multiplexing
- Connection pooling
- Memory-efficient design- **Configuration**
- Multiple port binding
- Custom error pages
- Route-based rules
- Directory restrictions
- Upload size limits## Architecture
```mermaid
sequenceDiagram
participant Client
participant Listener as Server Listener
participant Poller as Polling Mechanism
participant Handler as Request Handler
participant Router
participant Methods as HTTP Methods
participant Static as Static File Server
participant CGI as CGI Handler
participant Error as Error Handler
participant Response as Response GeneratorClient->>Listener: Connect to Server
Listener->>Poller: Register Socket
Poller-->>Listener: Socket Ready
Listener->>Handler: Accept Connection
Handler->>Poller: Register Client Socket
Poller-->>Handler: Data Ready
Handler->>Client: Read HTTP Request
Handler->>Router: Parse Request
Router->>Router: Match Route
alt Request Type
opt Static Content
Router->>Static: Retrieve File
Static-->>Handler: Serve File
end
opt Execute CGI
Router->>CGI: Run Script
CGI-->>Handler: CGI Output
end
opt Unsupported Method
Router->>Error: Generate Error
Error-->>Handler: Error Response
end
end
Handler->>Response: Generate HTTP Response
Response->>Client: Send Response
Client-->>Handler: Acknowledgment
Handler->>Poller: Remove Socket if Done
```## Preview
![preview](https://github.com/user-attachments/assets/3374181a-a4fc-4380-b3a4-80c0b25513f7)
## Quick Start
```bash
# Build the server
make# Run with default config
./webserv config/default.conf# Test basic functionality
curl http://localhost:8080/
```## Configuration Example
```nginx
server {
port 8080;
server_name localhost;
root /var/www;location / {
index index.html;
methods GET POST;
}location /cgi-bin {
allowed_methods GET POST;
client_max_body_size 10M;
cgi_pass /usr/bin/python3;
}
}
```## Requirements
- C++98 compiler
- POSIX-compliant system
- CMake 3.0+ (for building)## `siege` stress test
```bash
> siege -b 127.0.0.1:8080/empty.html -t10s
# macOS
Transactions: 136047 hits
Availability: 100.00 %
Elapsed time: 10.76 secs
Data transferred: 0.00 MB
Response time: 1.97 ms
Transaction rate: 12643.77 trans/sec
Throughput: 0.00 MB/sec
Concurrency: 24.89
Successful transactions: 136047
Failed transactions: 0
Longest transaction: 30.00 ms
Shortest transaction: 0.00 ms
# ubuntu
Transactions: 94641 hits
Availability: 100.00 %
Elapsed time: 9.56 secs
Data transferred: 0.00 MB
Response time: 0.00 ms
Transaction rate: 9899.69 trans/sec
Throughput: 0.00 MB/sec
Concurrency: 24.61
Successful transactions: 94641,
Failed transactions: 0
Longest transaction: 0.01 ms
Shortest transaction: 0.00 ms
```---
This project is part of the 42 school curriculum.