How swangarch/42webserv works
Project type and purpose
• This is a custom, standalone HTTP/1.1 web server written in C++98, inspired by Nginx, supporting:
• Multiple virtual hosts
• Static file serving
• Dynamic content via CGI (PHP, Python, …)
• Custom configuration file syntax
• IO multiplexing with epoll
• HTTP methods GET, POST, HEAD, DELETE
File structure
• Top-level:
• config/default.conf – the server’s routing and host configuration
• includes/… – C++ header files for ConfigManager, Location, ServerInfo, error handling, server core
• srcs/config/… – implementations for parsing config and building in-memory config objects
• srcs/main.cpp – entry point; initializes ConfigManager, constructs server instances, runs event loop
• srcs/server/… – (presumed) HTTP server core: socket setup, epoll loop, request parsing, dispatch
• site/… – sample content tree for several virtual hosts (web1, web2, web3), including static assets, CGI scripts, error pages
• test.sh – automated testing script
Additional insights from README
• Key components mentioned:
• Single‐threaded, epoll-based event loop
• Persistent connections and chunked transfer
• CGI support via child processes, pipes for stdout/stderr
• Virtual host resolution by ip:port and server_name
• Modules for autoindex, alias, redirection, upload handling, error pages
• Timeouts for requests and CGI
Elements
Client → Listener/epoll → Parser → Router → (Static Handler or CGI Handler) → Response Builder → epoll → Client
• Notes or annotations on edges for key protocols or data formats (HTTP/1.1, chunked, CGI env vars)