A lightweight, non-blocking HTTP server written in C++98, compliant with HTTP 1.1 standards. Designed to handle static content, file uploads, CGI scripts, and more. Includes bonus features like session management and multiple CGI support.
- Features
- Installation
- Usage
- Configuration
- Testing
- Bonus Features
- Limitations
- License
- Acknowledgments
- Resources
- HTTP/1.1 Compliance: Supports GET, POST, DELETE methods, chunked transfers, and error handling.
- Non-Blocking I/O Multiplexing: Uses
epoll()
for efficient client-server communication. - Static Website Hosting: Serve static files (HTML, CSS, JS, images) with directory listing options.
- File Uploads: Accept client file uploads via POST requests.
- CGI Support: Execute scripts (e.g., PHP, Python) with proper environment setup.
- Configurable: Inspired by NGINX syntax for defining ports, routes, error pages, and client limits.
- Resilient: No crashes allowed, even under memory constraints.
- Bonus: Session management, cookies, and multiple CGI handlers.
- C++98-compatible compiler (e.g.,
g++, clang
) make
- Testing tools:
curl
, web browser, siege, or custom scripts (Python/Go).
- Clone the repository:
git clone https://github.com/yourusername/webserv.git cd webserv
- Compile using the provided Makefile:
Output:
make
./webserv
Run the server with an optional configuration file:
./webserv [config_file.conf]
If no file is provided, the server uses a default configuration (see configurations/default.conf
).
You can run it with docker too:
# ensure that you have docker or docker desktop installed and running in your machine!
make up # run program in a docker container with a hand made hot reload.
Configure ports, routes, error pages, and more using an NGINX-style file. Example:
http{
client_max_body_size 10M;
autoindex on;
root ./var/www/html;
server{
listen 8090;
server_name phpserver;
location /
{
web_dav on;
limit_except GET POST {
deny all;
}
error_page 404 /404.html;
fastcgi_pass /usr/bin/php-cgi;
fastcgi_extension php;
}
location /deletable {
web_dav on;
limit_except POST DELETE {
deny all;
}
}
location /coffee {
return 418;
}
}
server{
listen 8092;
server_name meusite;
location / {
root var/www/html;
}
}
Key options:
listen
: Port and host (e.g.,127.0.0.1:8080
).client_max_body_size
: Max upload size.limit_except
: Allowed HTTP methods per route.fastcgi_pass
: Define cgi path.fastcgi_extension
: Map file extensions to executables.
-
Basic Checks:
curl http://localhost:8080
-
Stress Testing: Use tools like Siege Bench:
siege -b -t 60s http://localhost:8090/
-
Browser Testing: Open
http://localhost:8090
in a browser. -
Google Test Lib:
make test
- Cookies & Sessions: Track user sessions using cookies. Example config:
- Multiple CGI Handlers: Run Python, PHP, and other scripts simultaneously.
- No regex support in route paths.
- Limited to HTTP/1.1 features outlined in the RFC (no WebSocket or HTTP/2).
Distributed under the MIT License. See LICENSE
for details.
- Inspired by NGINX configuration syntax.
- RFC 7230/7231 for HTTP standards.
- 42 School for the project guidelines.
- RFC STD
- MDN
- Beej’s Guide to Network Programming
- Computer Networks Tanembaum
- TCP vs UDP
- Simple Http Server
- Jacob Sorber Video
- How the web works: HTTP and CGI explained
- MIME
- HTTP Status Codes
- How to Read an RFC
- RFC 9110 - HTTP Semantics
- RFC 9112 - HTTP/1.1
- RFC 2068 - ABNF
- RFC 3986 - (URI) Generic Syntax
- RFC 6265 - HTTP State Management Mechanism (Cookies)
- RFC 3875 - CGI
- Python web Programming
- CPP web Programming
- (Video) Creating a file upload page
- URL Encoding
- Nginx
- (Video) IO Multiplexing
- IO Multiplex
- Tests using CMake
- (Video) Async vs Multithreading
- Nginx Source Code