Web Programming

HTTP Server: File Delivery

The objective of this exercise is to complete the HTTP server so that it can deliver files.

Tasks

  1. Parse the HTTP request line to determine the HTTP method and the request path.
  2. If the method is not GET, return the error status 405 (Method Not Allowed).
  3. Read the file specified in the request path and write its content into the HTTP response body.
  4. If the file does not exist, return the error status 404 (Not Found).
  5. (Optional) Add the headers Content-Type and Content-Length to the response.
  6. (Optional) If the request path designates a directory, deliver an index file.

Solution