The Webserv project involves creating your own HTTP server in C++ 98. The server must:
- Be able to process HTTP requests and serve responses.
- Allow testing with a web browser.
- Comply with specific requirements, ensuring stability and resilience.
HTTP is a foundational protocol for data communication on the World Wide Web, making this project invaluable for understanding web technologies.
-
Makefile:
- Must compile source files without relinking unnecessarily.
- Required rules:
$(NAME),all,clean,fclean,re.
-
Compilation:
- Use
c++with-Wall -Wextra -Werrorflags. - Code must comply with the C++ 98 standard.
- Use
-
Preferred Practices:
- Use C++ features over their C equivalents (e.g.,
<cstring>over<string.h>).
- Use C++ features over their C equivalents (e.g.,
-
Prohibited Libraries:
- No external libraries or Boost libraries are allowed.
- Name:
webserv - Files: Must include
Makefile, headers (*.h, *.hpp), implementation files (*.cpp, *.tpp, *.ipp), and configuration files. - Execution:
./webserv [configuration file] - External Functions:
- Allowed:
execve,dup,dup2,pipe,strerror,gai_strerror,errno,fork,socketpair,htons,htonl,ntohs,ntohl,select,poll,epoll(and variants),kqueue(and variants),socket,accept,listen,send,recv,chdir,bind,connect,getaddrinfo,freeaddrinfo,setsockopt,getsockname,fcntl,close,read,write,waitpid,kill,signal,access,stat,open,opendir,readdir, andclosedir.
- Allowed:
-
Core Features:
- Handle HTTP methods:
GET,POST, andDELETE. - Serve a fully static website.
- Enable file uploads.
- Default error pages if none are provided.
- Compatibility with modern web browsers.
- Handle HTTP methods:
-
Behavior:
- Must be non-blocking and use only one
poll()(or equivalent) for all I/O operations. - Ensure accurate HTTP response status codes.
- Stress-test the server to guarantee availability under load.
- Support listening on multiple ports.
- Must be non-blocking and use only one
-
Restrictions:
- Cannot use
forkfor purposes other than CGI execution. - Must unchunk
chunkedrequests for CGI processing.
- Cannot use
- Define ports and hosts for servers.
- Specify server names (optional).
- Set up default error pages and client body size limits.
- Define route-specific settings, such as:
- Accepted HTTP methods.
- HTTP redirection rules.
- Directory/file mapping for URL paths.
- Directory listing toggles.
- CGI execution based on file extensions.
- File upload locations.
- Use
fcntl()for non-blocking file descriptors. - Permitted flags:
F_SETFL,O_NONBLOCK,FD_CLOEXEC.
Bonus features include:
- Support for cookies and session management.
- Handling multiple CGI programs.
-
Testing:
- Compare server behavior with NGINX.
- Use tools like Telnet and Python scripts to simulate client requests.
- Verify against the HTTP/1.1 specification for compliance.
- ...
-
Documentation:
- Provide configuration files and example content to demonstrate server functionality.