Using TCP sockets, you will write a simplified version of a HTTP client and server. The client program will use the HTTP protocol to download a file from the server using the HTTP GET method, and then subsequently use conditional GET operations to download the file only if it has been modified.
The HTTP client will perform the following functions:
Take in a single command line argument that specifies a web url containing the hostname and port where the server is running, as well as the name of the file to be downloaded, in the appropriate format. Example: localhost:12000/filename.html
Use a HTTP GET operation to download the file named in the URL
a. Print out the contents of the file
Use a Conditional GET operation to download the file named in the URL again
a. If the server indicates the file has not been modified since step 2, print output saying so (not necessary to print out file again)
b. Otherwise, the behavior is the same as 2a)
The HTTP server will perform the following functions:
Open a TCP socket and listen for incoming HTTP Get and Conditional GET requests from one or more HTTP Clients
In the case of a HTTP Get request:
a. Read the named file and return a HTTP GET Response, including the Last-Modified header field
In the case of a HTTP Conditional Get Request:
If the file has not been modified since that indicated by If-Modified-Since, return the appropriate Not Modified response (return code 304)
If the file has been modified, return the file contents as in step 2
In the case that the named file does not exist, return the appropriate "Not Found" error (return code 404)
Simplifying Assumptions:
Only GET and Conditional GET requests need be supported in client and server
Only a subset of header fields need to be supported in HTTP Requests and Responses (see Message Format section)
However, the server must ignore all header fields it does not understand. For example, a "real' web browser will send many more header fields in GET requests than those expected to be implemented by the server. The server MUST ignore these fields and continue processing as if these fields were not part of the GET request. The server MUST NOT report an error in these cases.
Test Cases:
1) Using your HTTP client, download the contents of a text-based html file named filename.html from your HTTP server using the appropriate URL. Example: localhost:12000/filename.html. The client must:
a. Print out the contents of the header in the HTTP Request
b. Print out the contents of the header in the HTTP Response
c. Print out file contents (you can print "as is". No formatting is required)
2) File remains unmodified since Step 1. Using your HTTP Client, send a conditional GET request to your HTTP server. The client must:
a. Print out the contents of the header in the HTTP Request
b. Print out the contents of the header in the HTTP Response, indicating file is not modified.
3) Requested file does not exist. Using your HTTP Client, send a GET request for a filename that does not exist. The client must:
a. Print out the contents of the header in the HTTP Request b. Print out the contents of the header in the HTTP Response