juzzrespecter / 42cc-webserv

Part of 42 common core cursus: develop a simple HTTP-compilant web server, fully compatible with a web navigator.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

webserv

[ Made with ❤️ by @danrodri and @fgomez-s ]



"I predict the Internet, (...) will soon go
spectacularly supernova and in 1996 catastrophically collapse."

~ Robert Metcalfe



Part of 42 common core cursus: develop a simple HTTP-compilant web server, fully compatible with a web navigator.

This project consists in developing in C++ a fully functioning web server, capable to serve at least a fully static website. For this, we kept in mind nginx as a reference, to compare header response behavior and configuration file structure.
Webserv will try to read a configuration file passed as a parameter [ or search in a default path if given none ], and if successful, will set up a series of servers [ opened sockets for listening to new connections ] with proper config. such as root folder in server host filesystem or a default error page.

The main interest on this project is in its core loop; as we are working with just one process without threads, webserv must be implemented using a multiplexing technique to be able to serve fairly to all clients and avoid server hangups.
The server will work with non-blocking sockets and will use select as a multiplexing tool to monitor events in listening and connection sockets.

Lastly, webserv must be fully compliant with the HTTP protocol [ HTTP 1.1 ], and must be compatible with CGI scripts.

Configuration file

Below there is a configuration file example for webserv.

server {
       listen 8080 ;
       server_name server_1;

       root ./html ;
       cgi_pass pl cgi-bin/perl;
       cgi_pass py cgi-bin/python3;

       error_page 404error.html ;
	   
       location /post_test {
       		client_max_body_size 30 ;
		accept_method GET POST HEAD;
       }
       location /cgi_test {
       		accept_method GET POST ;
       }
       location /noticias {
       		return http://www.42madrid.com ;
       }
}

server {
       listen 8989;
       server_name server_2;

       location /cookie_test {
       		accept_method POST GET;
		cgi_pass pl cgi-bin/perl;
       }
}

Configuration file options implemented:

  • Listen
    Sets up port and host of a virtual server.
  • error_page
    Sets up a default personalized 404 error page option.
  • Client_max_body_size
    Sets payload limit size for a request, will refuse any request bigger that this.
  • Location
    Sets routes for specific configuration inside a virtual server [ as in nginx ].
  • Accept_method
    List of accepted methods [ methods currently implemented in webserv are HEAD, GET, POST, PUT and DELETE ].
  • Return
    Sets up page redirection in location.
  • Root
    Sets up root directory for file searching.
  • Alias
    Sets alias for root directory in a route.
  • Autoindex
    Sets ON | OFF file listing on a directory if an index file is not present.
  • Index
    Sets index page searching for a directory.
  • Accept_cgi
    Sets up list of allowed scripts and path to binary script execution. Must be present file extension of resource and path to script interpreter
  • Accept_upload
    Sets a default upload directory used with a PUT request.

Usage

make && ./webserver [path_to_conf_file]



> Project passed with [125/100] mark ✅😎 <

About

Part of 42 common core cursus: develop a simple HTTP-compilant web server, fully compatible with a web navigator.


Languages

Language:C++ 86.8%Language:HTML 3.4%Language:Shell 2.8%Language:PHP 2.3%Language:Perl 2.2%Language:Dockerfile 1.2%Language:Makefile 1.1%Language:Python 0.2%