andersch.dev

<2023-04-10 Mon>
[ web ]

Web Server

A web server is the software responsible for handling HTTP requests from client connections.

Steps to implement a web server

  1. Basic TCP sockets layer: Listen on ports, accept client connections & send/receive data
  2. Implement a buffered reader so that you can read requests one line (delimited by CRLF) at a time.
  3. Read the very first line. Parse out the method, the request version and the path.
  4. Implement header parsing for the "Header: value" syntax. Don't forget unfolding folded headers.
  5. Check the request method, content type and content size to determine how/if the body will be read.
  6. Implement decoding of content based on content type.
  7. If you're going to support HTTP 1.1, implement things like "100 Continue", keep-alive, chunked transfer.
  8. Add robustness/security measures like detecting incomplete requests, limiting max number of clients etc.
  9. Shrink wrap your code and open-source it :)

Source: https://stackoverflow.com/questions/176409/build-a-simple-http-server-in-c

Resources