Skip to content

Moustachestache/webserv

Repository files navigation

Caution

THIS SERVER DOES NOT IMPLEMENT RFC 1149 DUE TO LACK OF AVAILABILITY
more info: https://datatracker.ietf.org/doc/html/rfc1149

Gbricot, Yoshi and Odiachen posing after having finished Webserv. Mjochum not pictured.

introduction

"Webserv" is the penultimate group project for the common core of 42.
In it you use C++98 to implement an HTTP server that manages POST, GET and DELETE methods, as well as a CGI (common gateway interface) and cookies.

process

This project required a lot of reading and preparation.
After a week of researching, we got a simplistic roadmap of goals. The roadmap went as follows:

  1. Read up documentation and interview other students on their approach and the pitfalls they encountered.
  2. Setup basic sockets you can ping by connecting to 0.0.0.0:8080
  3. Add an intelligible HTTP response
  4. Send back correct GET request
  5. Implement remaining methods (POST and DELETE)
  6. Executable python and bash script on server
  7. Cookies and sessions? sure let's just hammer them in.

what the code does

function what it do
Cgi.cpp Handles executing CGI scripts. Passes the HttpReaquests' variables (http, post, get and files) to the executable program.
Httpheader Receives HttpRequests. Processes it into an object for use later by parsing the incoming message from the client, and then if there is a need parses the body (if POST and Content-Size is relevant).
Creates a vector with the header variables to pass to the CGI for the program's argv.
Socket Object that handles the connection information.
Prog Runs the program. High level logic of server.
Route Each defined route is stored here and retreive when needed for redirections.
Server
& TcpServer
Class and its inherited class. Used to identify each server and have the run independantly.
Cookies Part of TcpServer. Handles cookies.
HttpError Probably the dumbest thing in this code. Mjochum decided early that HttpErrors had to be an object. This allows for storing custom error pages and creating error messages to return to the server.
exception Exception handler.

4 links that'll get you there

links
Oreilly's definitive guide to HTTP The single greatest piece of reading you can find. The first 5 chapters teach you 80% of what you have to code.
I have come to refer to this book as "the bible".
https://datatracker.ietf.org/doc/html/rfc2616 This is the base document defining everything there is to know about HTTP/1.1.
If ever a question pops up, the answer is here. and if it isn't, check again.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers A very easy-to-digest writeup by the mozilla foundation regarding the content of a header.
The website also references all the headers that could be used.
https://www.rfc-editor.org/rfc/rfc3875.txt A good reference document regarding the CGI.

more links

On connections, select and sending/receiving packets:
C++ http server writeup
https://osasazamegbe.medium.com/showing-building-an-http-server-from-scratch-in-c-2da7c0db6cb7
regarding sockaddr_in
https://www.gta.ufrj.br/ensino/eel878/sockets/sockaddr_inman.html
http://www.ccplusplus.com/2011/10/struct-sockaddrin.html
regarding select()
https://www.lowtek.com/sockets/select.html
Sockets (Juliusz Chroboczek, Universite Paris Diderot)
https://www.pps.jussieu.fr/~jch/enseignement/sockets.pdf
On the Common Gateway Interface (CGI):
CGI on Wikipedia
https://en.wikipedia.org/wiki/Common_Gateway_Interface
More on CGI
http://www.mnuwer.dbasedeveloper.co.uk/dlearn/web/session01.htm
some video on cgi
https://www.youtube.com/watch?v=sSy5EdRd7zc&ab_channel=Homedeve
regardeing CGI variables and how to pass them
https://www6.uniovi.es/~antonio/ncsa_httpd/cgi/env.html
On the configuration file:
NGINX default .conf
https://www.nginx.com/resources/wiki/start/topics/examples/full/
apache server Documentation
https://httpd.apache.org/docs/current/
On the Universe, life and everything:
get and post
https://www.ionos.fr/digitalguide/sites-internet/developpement-web/get-vs-post/
practical to fetch mime types
https://mimetype.io/all-types
redundant but more on http
https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview

About

HTTP server that is c++98 compliant

Resources

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •