Java Web Applications
HTTP Server: File Delivery
The objective of this exercise is to complete the
HTTP server so that it can deliver files.
Tasks
-
Parse the HTTP request line to determine the HTTP method and the request path.
-
If the method is not
GET
, return the error status 405 (Method Not Allowed).
-
Read the file specified in the request path and write its content into the HTTP response body.
-
If the file does not exist, return the error status 404 (Not Found).
-
(Optional) Add the headers
Content-Type
and Content-Length
to the response.
-
(Optional) If the request path designates a directory, deliver an index file.
Solution