Skip to content

linhtng/Webserv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

334 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Webserv

About

This project is about writing your own HTTP web server from scratch. The web server can handle HTTP GET, HEAD, POST, and DELETE Requests, and can serve static files from a specified root directory or dynamic content using CGI. It is also able to handle multiple client connections concurrently with the help of poll().

Usage

make
./webserv [Config File] ## ready-made config files can be found in configs/

Workflow

  • 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 method GET, the request target /index.html, and the HTTP version HTTP/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
  • 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

Resources

Networking

HTTP

General

CGI

About

This project is about writing your own HTTP server.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors