A work-in-progress HTTP/1.1 web server written in C++17 for the 42/CODAM
webserv project. The server is event-driven: it uses non-blocking sockets
and poll() to serve multiple clients without one connection blocking the
others.
The following functionality is implemented and covered at least in part by the included unit tests:
- HTTP/1.0 and HTTP/1.1 request handling, including keep-alive behaviour.
- Non-blocking TCP server with
poll()-based I/O. - Multiple
serverblocks on one port and virtual-host selection through theHostheader. - Parsing of server and location configuration blocks.
- Static-file delivery with MIME-type detection, index-file lookup, optional directory listing, custom error pages, and path-traversal checks.
GET,POST, andDELETE, controlled per location withallow_methods.- Request bodies sent with
Content-LengthorTransfer-Encoding: chunked. - Binary uploads to
upload_store;multipart/form-datauploads save the first part that has afilenameparameter. - Configurable request-body limits and standard error responses such as 400, 403, 404, 405, 413, 500, 501, and 505.
cgi_extension, cgi_path, and return are accepted by the configuration
parser, but CGI execution and redirect handling are not connected to the
response path yet. They should therefore be considered unfinished.
- A C++17-compatible compiler (
c++) make- A POSIX-compatible system (the current implementation uses sockets,
poll(), and POSIX filesystem APIs)
make
./webservWithout arguments, the server reads ./config/default.conf. To use another
configuration file:
The default configuration listens on port `8080`. With the supplied site
files available, try:
```sh
curl -i http://127.0.0.1:8080/
make testThe current test suite verifies configuration parsing, request parsing, response serialization, request buffering, chunked-body decoding, virtual hosts, body-size limits, and binary upload handling. The test suite passes in the supplied project snapshot.
The syntax follows the familiar server / location block structure:
server {
listen 8080;
server_name localhost;
root ./site/www;
index index.html;
client_max_body_size 1000000;
error_page 404 /error_pages/404.html;
location / {
allow_methods GET;
autoindex off;
}
location /upload {
allow_methods GET POST DELETE;
upload_store ./site/www/uploads;
autoindex on;
}
}Supported server directives are listen, server_name, root, index,
client_max_body_size, and error_page. Supported location directives are
allow_methods, upload_store, autoindex, root, index,
cgi_extension, cgi_path, and return.
For file uploads, create the configured upload directory before starting the server; it is not created automatically:
mkdir -p site/www/uploads
curl -i --data-binary @./photo.webp http://127.0.0.1:8080/uploadmain.cpp Application entry point
code/ Server, parsing, request, response, and upload code
code/hpp/ Headers
config/ Example server configurations
site/ Static website and error-page assets
tests/ Unit tests and configuration fixtures
- Ivan Pavlov — 12Ivan03
- Anastasia Erokhina — agerokhina
make # build webserv
make test # build and run unit tests
make clean # remove object and dependency files
make fclean # also remove binaries
make re # rebuild the server