Question
In python, using TCP sockets, you will write a simplified version of a HTTP client and server. The client program will use the HTTP protocol
In python, 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, cache it, 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
If the file is not yet cached, use a HTTP GET operation to download the file named in the URL
Print out the contents of the file
Cache the file
If the file is cached, use a Conditional GET operation for the file named in the URL
If the server indicates the file has not been modified since last downloaded, print output saying so (no need to print file contents in this case)
Otherwise, indicate that the file has been modified, and print and cache new contents
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:
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)
The server must ignore all header fields in HTTP Requests it does not understand
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 client and 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.
Cache Implementation:
The cache must be implemented as a file so that it persists across client instantiations
The file(s) used to implement the cache must include cache in the filename so that it is easy to distinguish e.g cache.txt
The program must work as per the test cases across multiple client instantiations, one per test case.
The client program must work if the cache file does not exist (in which case, the implication is no files have been cached)
Note that this means the file may have existed after previous runs of your program, but has since been deleted prior to client restarting
As part of this assignment, your HTTP Client and HTTP Server programs are only expected to handle the following header fields:
HTTP Client GET Request Message:
Your GET Request must include the following:
Request line containing method (GET) , object (from URL) and version (HTTP1.1)
Host: includes hostname (and port, if specified, separated by :)
Blank line: signifies ends of header, expressed by \
HTTP Server Response to Client GET Request (assuming file exists):
The response from the HTTP Server must include the following:
Status line including version (HTTP1.1), status code (200), and status phrase (OK)
Date: header field containing current date and time in the following format (must be UTC/GMT time zone):
Example of Date format: Mon, 23 Jan 2017 15:55:47 GMT
Last-Modified: header field containing date and time file was last modified. Must follow same format as Date: above
Content-Length: length of data in bytes
Content-Type (can be hard-coded): text/html; charset=UTF-8
Blank line: signifies ends of header
Body: Contents of requested file
HTTP Client Conditional GET Request Message:
Your GET Request must include the following:
Request line containing method (GET), object (from URL) and version (HTTP1.1)
Host: Same as in GET request
If-Modified-Since: Echo back value of Last-Modified time in HTTP GET Response
Blank line: signifies ends of header
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started