Custom HTTP server implemented in C++ following HTTP/1.1 semantics.
This README provides usage and configuration information, lists bonus/demo features present in the assets/ folder, and includes a short design review (SOLID-style) describing how the codebase maps to common software design principles.
Webserv is an educational HTTP server that accepts connections, parses requests, executes CGI scripts, and serves static files. It supports multiple simultaneous connections and the basic HTTP methods used in teaching exercises.
- HTTP/1.1 request parsing and response generation
- Non-blocking I/O with an Epoll-based event loop
- Supported methods:
GET,POST,DELETE - Configurable server and location blocks via a
.conffile - Static file serving and directory index handling (autoindex)
- CGI execution (multiple interpreters supported by configuration)
- Redirections and custom error pages
- Request size limits and basic input validation
- Mime type detection
Under assets/www/ you will find example pages and scripts used for testing and demos:
index/,login/,register/— demo pages and simple formsupload/andportal/— upload/management demo pages and server-side handlerscgi-bin/— example CGI scripts (.php,.py, compiled test programs)download/— example downloadable fileserror_page/— custom error page assetsconfig_files/(located atassets/config_files/, directly underassets/) — example configuration files used in tests (should_work.conf,test_server.conf, etc.)
Run from the webserv/ directory:
make # Build the server
make clean # Remove object files
make fclean # Remove all build artifacts
make re # Rebuild from scratch./webserv <config_file.conf>The program currently expects exactly one argument (a config file path). See assets/config_files/ for example configs.
server {
listen 989;
server_name example.com;
location /
{
root /var/www/html;#hola
index index.html;
}
listen pepe;
location /api{
proxy_pass http://backend;
}
server {
listen test_error;
}
listen 8080;
}}
Supported methods:
| Method | Description |
|---|---|
| GET | Retrieve a resource |
| POST | Send data to the server (e.g., file upload) |
| DELETE | Remove a resource |
Common response codes returned by the server:
200 OK— Success301/302— Redirect400 Bad Request— Malformed request403 Forbidden— Permission denied404 Not Found— Resource not found405 Method Not Allowed— Unsupported method413 Payload Too Large— Request exceeds size limits500 Internal Server Error— Server-side error
- C++ compiler (g++ / clang++)
- C++98 or later (codebase uses classic C++ style; incremental modernization recommended)
make- POSIX-compatible OS (Linux / macOS)
- Non-blocking sockets with
fcntland Epoll - Event loop dispatching accept/read/write using
EpollManagerandEventLoop - Socket lifecycle handled by
SocketsManager - Request parsing and header handling in
HttpRequestManager - Response construction in
ResponseFactory(including custom error pages) - CGI handling with environment setup (
CgiEnvBuilder,CgiHandler) - Config parsing/building using a Builder/Composite pattern (
ServerBuilder,LocationBuilder,AConfigBlock)
Use curl to exercise endpoints (examples):
curl http://localhost:8080/
curl -X POST -d "hello" http://localhost:8080/upload
curl -X DELETE http://localhost:8080/somefile.txt
curl -v http://localhost:8080/index.htmlThis project uses several well-known patterns (Factory, Strategy, Builder, Composite) and modular directories (builder/, factory/, strategy/, execute/, composite/) which map well to separation of concerns.
- Single Responsibility (S): Generally respected — classes like
ServerBuilder,SocketsManager,HttpRequestManager, andResponseFactoryhave focused responsibilities. - Open/Closed (O):
StrategyFactoryand registration functions allow adding new validation/strategy implementations without modifying existing consumers. - Liskov Substitution (L): Base interfaces (e.g.,
IConfigBuilder,IValidationStrategy,IHttpRequestHandle) are used; derived classes appear to be substitutable in current usage. - Interface Segregation (I): The code defines multiple small interfaces (e.g.,
IValidationStrategy,IConfigBuilder), which keeps consumers from depending on unused methods. - Dependency Inversion (D): High-level modules use abstract interfaces and factories, but there is still frequent use of raw
new/deleteand concrete type construction. Consider injecting dependencies (or factories) where possible instead of constructing concrete dependencies deep in the call stack.
From inspection the codebase implements:
- Configuration parsing into
ServerConfig/LocationConfigstructures (Builder/Composite) - Strategy-based validation and directive handling (StrategyFactory)
- Socket creation and non-blocking accept/listen (SocketsManager)
- Event-driven loop with epoll integration (EventLoop / EpollManager)
- HTTP request parsing, header handling and basic validation (HttpRequestManager)
- Response creation including custom error pages and basic mime detection (ResponseFactory / MimeTypeDetector)
- CGI environment building and execution (CgiEnvBuilder / CgiHandler)
- Static file serving, downloads, uploads and directory indexing (implemented in response logic)
Last updated: December 2025