This project is about writing your own HTTP server.
- Setting up the server for basic reading and writing operations
- set up the server socket, bind it to a port, and start listening for incoming connections. When a connection is accepted, it should spawn a new thread to handle the connection
- Parsing what we exchange with the clients (i.e. messages)
-
Reading the Request from the socket using a function like
recv()
-
Parsing the Request Line: The first line of the request is the request line, which contains the HTTP method (GET, POST, etc.), the request target (usually a URL or file path), and the HTTP version. For example, parsing the request line
GET /index.html HTTP/1.1
, to extract HTTP methodGET
, the request target/index.html
, and the HTTP versionHTTP/1.1
-
Parsing the Headers: After the request line, the request contains several headers, which provide additional information about the request. These are formatted as
Name: Value
. -
Parsing the Body: If the request is a POST request, it will have a body after the headers. This will contain the data for the file upload.
-
- Implementing logic to handle different HTTP methods, process requests, and generate appropriate responses
- Handle GET Request with the requested file path from parsing:
- Locate the file on the disk
- Read the file into memory
- Send the file over the connection
- Handle POST Request with the file data and the destination file path from parsing:
- Write the file data to the specified file on the disk
- Send a response confirming the upload
- Handle GET Request with the requested file path from parsing:
- CGI handling
- Implement support for executing CGI scripts and returning their output in the HTTP response
- Configuration files
- Testing:
- default basic files to test and demonstrate every feature works
- script(s) to check CGI
- simple website to test the server
- Logging (Optional):
- to log everything happened in the server
Networking
- Beej's Guide to Network Programming
- webserv: Building a Non-Blocking Web Server in C++
- Socket Programming in C
- Explores epoll
- Using poll() instead of select()
HTTP
General
- https://github.com/Bima42/webserv
- https://github.com/Kaydooo/Webserv_42
- https://stackoverflow.com/questions/10631933/nginx-static-file-serving-confusion-with-root-alias
CGI