A complete HTTP/1.1 server implemented in C++98 as part of the 42 school Webserv project.
Webserv is an asynchronous non-blocking web server capable of handling multiple simultaneous clients through an event-driven architecture based on poll(). It implements the main features of a modern HTTP server including virtual hosting, CGI execution, and request handling.
- Supported methods: GET, POST, DELETE
- Chunked transfer encoding
- Timeout management: headers, inactivity, CGI
- Complete HTTP status codes (2xx, 3xx, 4xx, 5xx)
- Standard HTTP headers with automatic MIME type detection
- File serving with efficient streaming
- AutoIndex: HTML generation of directory listings
- Automatic MIME type detection
- File upload
- Automatic unique filename generation
- Write permission verification
- Request body parsing with size limits
- File/directory deletion
- Security checks for accessible paths
- Process forking with pipe communication
- Standard CGI environment variables
- Configurable execution timeout (4s default)
- Complete CGI response header handling
- Multi-server: multiple servers in one instance
- Selection by:
- IP:Port binding
- Hostname via Host header
- Multiple locations with path matching
- Hierarchical configuration with value inheritance
- Event-driven architecture with poll() loop
- Non-blocking I/O on all sockets
- Multiplexing: up to 100 simultaneous clients
- State management: requests and responses with state machine
# With default configuration
./webserv
# With custom configuration file
./webserv path/to/config.confThe server uses an event-driven model with multiplexing:
- Main loop with
poll()(1000ms timeout) - Non-blocking I/O for all sockets
- Simultaneous handling of up to 100 clients
- Request/response states with state machine
WebServer (Singleton)
├── VirtualHost[] (virtual servers)
│ ├── BindingInfo (IP:Port)
│ └── Location[] (locations)
└── Client[] (connected clients)
├── HttpRequest (parsing)
├── HttpResponse (generation)
└── ARequestHandler (abstract handler)
├── MethodHandler (GET/POST/DELETE)
└── CGIHandler (CGI execution)
| Parameter | Value | Description |
|---|---|---|
| REQUEST_HEADERS_TIMEOUT | 4s | Header read timeout |
| INACTIVITY_TIMEOUT | 7s | Client inactivity timeout |
| CGI_EXECUTION_TIMEOUT | 4s | CGI execution timeout |
| MAX_CLIENTS | 100 | Maximum simultaneous clients |
| READ_BUFFER | 8192 | Read buffer size |
| WRITE_BUFFER | 8192 | Write buffer size |