A server developed by Larissa and Rodrigo, dedicated to sharing pictures of their dogs on the web.
The Webserv project is an HTTP server written in C++98, following the HTTP (Hypertext Transfer Protocol) protocol. HTTP is an application protocol that serves as the foundation for data communication on the World Wide Web, enabling the distribution of hypertext documents with hyperlinks to resources accessible through web browsers.
The main goal of this project is to implement an efficient and non-blocking HTTP server that can be configured through a configuration file. It can define ports, hosts, default error pages, request body size limits, and more. The server supports HTTP methods, including GET, POST, and DELETE, making it suitable for serving web pages and handling various HTTP requests.
To compile and run this project, you'll need the following items:
- C++ compiler with support for C++98 standard (GCC or Clang recommended).
sudo apt update && sudo apt install g++
- libcurl library (for HTTP request features).
sudo apt update && sudo apt install libcurl4-openssl-dev
To compile the project, follow these steps:
- Clone this repository to your local system.
- Make sure you have a C++ compiler installed on your machine.
- Make sure you have the libcurl library installed on your system.
- Navigate to the root directory of the project (where the Makefile is located).
- Run the
make
command to compile the project.
./webserv [configuration file]
-
Access the routes configured in the "conf/default.conf" file directly in the Firefox web browser.
-
Use browser developer tools to inspect HTTP requests and responses.
-
Try third-party tools such as Postman, Insomnia, or the "curl" command to send custom HTTP requests and check the responses.
- Default Configuration File
There is a default configuration file at the path conf/default.conf that contains initial server configurations.
./webserv conf/default.conf
- .conf File Extension
All configuration files must have the .conf extension for the system to recognize them correctly as configuration files.
- Restricted Comments
It's important to emphasize that configuration files should not include comments, and neither should they contain ";".
To specify the port on which the server will listen, use the listen
directive followed by the desired port number.
listen 8000
To define the root directory for the server, use the root directive and specify the path to the desired directory.
root wwwroot
To set the server names, use the server_names
directive followed by the desired server names, each on a separate line:
server_names lade-lim.42.fr
server_names localhost
To establish a limit for the size of the request body, use the body_size_limit directive and specify the desired value.
body_size_limit 6666666
To specify a custom error page for a specific error, mention the error you want to customize, followed by the desired error code, and the path to the new error page:
404 /index.html;
Location with definition of methods
location / {
http_methods 1; # Allows only the GET method (1)
index index.html; # Defines the index file for this location
}
location / {
http_methods 2; # Allows only the POST method (2)
index index.html; # Defines the index file for this location
}
location / {
http_methods 4; # Allows only the DELETE method (4)
index index.html; # Defines the index file for this location
}
location / {
http_methods 5; # Allows the methods GET (1) and DELETE (4)
index index.html; # Defines the index file for this location
}
location / {
http_methods 6; # Allows the methods POST (2) and DELETE (4)
index index.html; # Defines the index file for this location
}
location / {
http_methods 7; # Allows the methods GET (1), POST (2), and DELETE (4)
index index.html; # Defines the index file for this location
}
Location with CGI
location /cgi-bin {
http_methods 7; # Allows the methods GET (1), POST (2), and DELETE (4)
index cavalinho.html; # Defines the index file for this location
cgi_pass .py; # Specifies that .py files will be executed as CGI in this location
}
Location with directory_listing
location /directory {
directory_listing on; # Enables directory listing for this location
}
Location with redirection
location /redirect {
redirect index.html; # Defines a redirection to index.html
}