Skip to content
forked from itseugen/Webserv

Our own HTTP Server, coded in C++, able to handle GET, POST, DELETE Requests and CGI.

License

MKcodes2/Webserv

 
 

Repository files navigation

Webserv

A lightweight HTTP Server in My Skills

Team project created by: Eugen, Mary Kate & Dustin

📝 Description

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.


✨ Features

💡 Core Features:

  • 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.

🛠️ Configuration Options:

  • Server Setup:
    • Server name(s) defined (e.g., server_name, localhost).
    • Listening ports and hostnames configured.
    • Default servers assigned for each host:port.
  • 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 (.py in our case) with environment variable support.

🌟 Additional Features:

  • 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.

🎯 Requirements

  • 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.

    🚫 Forbidden Actions:

  • Blocking operations.
  • Using execve to invoke other web servers.
  • Reading or writing without using poll() first.
  • Checking errno after read or write.

⚙️ Installation

  1. Clone the repository:
git clone https://github.com/MKcodes2/Webserv.git
  1. Navigate to the project's directory:
cd Webserv
  1. Build the program:
make
  1. 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


🚀 Usage

🌐 The Webpage:

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 port 8080, 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 port 8081, 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 port 8082, allows all methods and has a big body size, but it doesn't redirect because the GET method is not configured in its redirections.

🖥️   LOGGER:

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

🛑 Termination of the Server:

You can close the server by simply clicking CTRL + C on the terminal where you initially ran the server by doing: ./webserv ...


🌱 Future Enhancements

  • 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.

📜 License

This project is released under the MIT License. Contributions are welcome!

About

Our own HTTP Server, coded in C++, able to handle GET, POST, DELETE Requests and CGI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 95.2%
  • HTML 2.7%
  • Makefile 1.9%
  • Python 0.2%