Webserv is our custom implementation of an HTTP/1.1 server written in C++17. Designed for efficiency and compliance with HTTP standards, our server supports non-blocking I/O operations and is compatible with modern web browsers. It offers essential functionality for hosting static and dynamic content while ensuring scalability and flexibility.
- Non-blocking I/O: Implements efficient I/O operations using
poll()for all client-server communication. - Multi-port Support: Ability to listen on multiple ports simultaneously.
- HTTP Methods Supported:
GET: Retrieve resources.POST: Upload data to the server.DELETE: Remove server-side resources.
- Default Error Pages: Provides default error pages for HTTP errors if custom ones aren't configured.
- Stress-Test Ready: Handles multiple simultaneous connections reliably without downtime.
- Server Setup:
- Server name(s) defined (e.g.,
server_name,localhost). - Listening ports and hostnames configured.
- Default servers assigned for each
host:port.
- Server name(s) defined (e.g.,
- Request Handling:
- Limit of client body size for uploads.
- HTTP method restrictions for specific routes.
- Directory listing enabled or disabled.
- Default files set for directory responses.
- HTTP redirections per route.
- Static and Dynamic Content:
- Static files are served from defined directories.
- Execution of CGI scripts (
.pyin our case) with environment variable support.
- File Uploads: Clients can upload files to designated directories.
- CGI Execution:
- Supports execution of scripts based on file extensions.
- Automatically handles chunked request decoding.
- Manages CGI output correctly, even without content-length headers.
- Stress Testing: Designed to remain operational under heavy load and large numbers of simultaneous requests.
- C++17 Standard: In our School we are limited to use everything up to C++17.
- Non-blocking Design: Ensures all I/O operations go through the
poll(). - Configuration File: The server accepts a configuration file as an argument or uses a default path if none is provided.
- Blocking operations.
- Using
execveto invoke other web servers. - Reading or writing without using
poll()first. - Checking
errnoafterreadorwrite.
- Clone the repository:
git clone https://github.com/MKcodes2/Webserv.git- Navigate to the project's directory:
cd Webserv- Build the program:
make- Run the Web-Server with the config file of your choice:
./webserv config_files/<file_of_your_choice> 💡 You can also run just ./webserv: in this case, the server uses a default configuration
You can access any of the configured servers in a web-browser by typing in the search-bar:
🔎 localhost:<port_it_listens_to>
For example, if you ran ./webserv which uses the default.conf, there are 3 servers configured there, that listen to the ports 8080, 8081, and 8082, respectively. So you could access them on the web-broswer by typing:
- localhost:8080, or
- localhost:8081, or
- localhost:8082
And according to what server you are accessing, you can browse/do different things there, depending on their configuration. For example in the default.conf:
server1, which listens to port8080, allows all methods, redirections (e.g. localhost:8080/google), and has a big body size, so there you can upload even large files.server2, which listens to port8081, allows all methods and redirections, but you can only upload small images up to 200KB and doesn't allow directory listing.server3, which listens to port8082, allows all methods and has a big body size, but it doesn't redirect because the GET method is not configured in its redirections.
You can view the webserver's output in the log directory, to keep track of the actions happening.
For example, this is the initial log when you launch the program by running ./webserv:
[20-11-2024:02:50:13] [INFO] Config file read
[20-11-2024:02:50:13] [INFO] Config file interpreted
[20-11-2024:02:50:13] [INFO] Socket Manager Constructor called
[20-11-2024:02:50:13] [INFO] server1: Constructor called
[20-11-2024:02:50:13] [INFO] server1: Server is now listening on 8080
[20-11-2024:02:50:13] [INFO] server2: Constructor called
[20-11-2024:02:50:13] [INFO] server2: Server is now listening on 8081
[20-11-2024:02:50:13] [INFO] server3: Constructor called
[20-11-2024:02:50:13] [INFO] server3: Server is now listening on 8082
You can close the server by simply clicking CTRL + C on the terminal where you initially ran the server by doing: ./webserv ...
- Cookie and Session Management: Support for client state management.
- Advanced CGI Handling: Simultaneous support for multiple CGI environments.
- HTTPS Support: Implementation of SSL/TLS for secure communication.
This project is released under the MIT License. Contributions are welcome!