Assignment 8- OPTIONAL Solution

$30.00

Description

/ Instructions

This is an optional assignment. It is 100% extra credit and worth 1 full assignment of points. Download the template Java program in Canvas: Files/WebServer.zip

Please compress your code and README.txt file into a zip file or tar.gz.

/ Programming Assignment

As is, the server will compile and listen on port 8080. It can be accessed by:

http://127.0.0.1:8080/

Currently, it will print the HTTP request header to the console window and simply send back Hello

World! (with no HTTP response header). I tested this with Firefox and Edge and it works well with both. You need to implement a web server which has the following functionality:

You need to implement HTTP 1.1 handling for GET and HEAD requestes

You need to figure out how to respond with HTTP 1.1 response headers

The server should treat the webroot subdirectory as the root directory for the web server… in other words, http://127.0.0.1:8080/ should point to the webroot directory

If a directory is the target and there is no file specified

o the web server should look for a file named index.html, if that file exists, then return

that object

o if there is no index.html file then your server needs to render a HTML page which

creates clickable links for the subdirectories and files. For example:

http://127.0.0.1:8080/ should render a page with two links:

• “add should point to http://127.0.0.1:8080/add

• “subdirectory should point to http://127.0.0.1:8080/subdirectory

If the directory is a subdirectory of the root directory, it should also have a link

.. which should point to the parent directory

Please note, http://127.0.0.1:8080/add should automatically load “index.html

Please note, http://127.0.0.1:8080/subdirectory should display a directory

listing with 4 files, as well as ..

Clicking on a file should load it in the browser (in other words, make sure to render the filename as a link to the URL of the file)

You should return different MIME types in the HTTP response header for different files (based on file extension). You need to at least handle TEXT and HTML

/ Tips

Start early!

Ask questions ask them in the discussion on Canvas first before asking me.

Help other students!

The IP address of your server is 127.0.0.1

The port of your server is 8080

I have provided you a basic Makefile this makes things simpler when compiling your program

Pay attention to things like MIME types in the HTTP header the browser will render content differently for different types

/ Additional Things You Could Do

Please note, these won’t garner you any extra credit, and are not required. However, they are things which may interest you (and will certainly teach you a lot about HTTP).

Handle images (and their corresponding MIME types)

Handle JSON (and MIME type)

Create / interface with a scripting library (like PHP)

Figure out how to handle POST (especially for file uploads)

/ Useful Links

https://www.w3.org/Protocols/rfc2616/rfc2616.html

https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol

https://www.tutorialspoint.com/http/http_responses.htm

https://www.thoughtco.com/file-extensions-andmime-types3469109