Write a simplified version of a http client and server

Assignment Help Computer Engineering
Reference no: EM131911151

Programming Assignment: Simple HTTP Client and Server

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:

1. 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

2. Use a HTTP GET operation to download the file named in the URL

a. Print out the contents of the file

3. 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:

1. Open a TCP socket and listen for incoming HTTP Get and Conditional GET requests from one or more HTTP Clients

2. 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

3. In the case of a HTTP Conditional Get Request:

a. If the file has not been modified since that indicated by If-Modified-Since, return the appropriate Not Modified response (return code 304)
b. If the file has been modified, return the file contents as in step 2

4. In the case that the named file does not exist, return the appropriate "Not Found" error (return code 404)
5. 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 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:

Enable wireshark during all the following test cases. One wireshark .pcap is fine for the test cases in this section.

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

Test Cases for extra credit:

Using a web browser, such as Firefox (note: Safari web browser may not implement the conditional GET as expected), perform the same operations as above to test your server. Enable wireshark during all the following test cases. One wireshark .pcap is fine for the web browser test cases.

1. Enter the URL in the web browser search bar and press <return>. The web browser should print the contents of the file downloaded from your server.

2. Re-enter the URL in the web browser search bar and press <return>. The web browser should show the same web page contents as in step 1 (assuming the file has not been modified.), and the wireshark trace should show a Conditional Get and a "Not Modified" response.

3. Modify the file.

4. Re-enter the URL in the web browser search bar and press <return>. The web browser should now show the updated web contents.

Message Format:

HTTP messages are encoded in ASCII as strings in a specific format defined according to the HTTP specification[1,2,3]. References on the HTTP Message Format can be found as follows:

• See textbook (Section 2.2.3) or lecture slides web.pdf on Moodle for general format of HTTP Request and Response messages and some examples, specifically slides 16-17 and 20-22.

• See textbook section 2.2.5 and slide 32 for information on HTTP Conditional Get

• Also, look at the wireshark trace provided as part of the assignment (HTTP_Conditional_Get_Example.pcapng) for an example of HTTP GET and Conditional GET requests.

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 "\r\n\"

Example:

GET /filename.html HTTP/1.1\r\n Host: localhost:12000\r\n
\r\n

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):

o 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

• Blank line: signifies ends of header

• Body: Contents of requested file

Example:
HTTP/1.1 200 OK\r\n
Date: Sun, 04 Mar 2018 21:24:58 GMT\r\n
Last-Modified: Sun, 04 Mar 2018 21:24:58 GMT\r\n Content-Length: 75\r\n
Content-Type: text/html; charset=UTF-8\r\n
\r\n
<html><p>First Line<br />Second Line<br />Third Line<br />COMPLETE<p><html>

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

Example:

GET /filename.html HTTP/1.1\r\n Host: localhost:12000\r\n
If-Modified-Since: Fri, 02 Mar 2018 21:06:02 GMT\r\n
\r\n

HTTP Server Conditional Response Message (Not Modified):
HTTP/1.1 304 Not Modified\r\n
Date: Sun, 04 Mar 2018 21:24:58 GMT\r\n
\r\n

HTTP Server Response when file not found:
HTTP/1.1 404 Not Found\r\n
Date: Sun, 04 Mar 2018 21:24:58 GMT\r\n
\r\n

Programming Hints: See references [4,5,6]

Get current time in UTC/GMT time zone and convert to string in HTTP format:
import datetime, time
t = datetime.datetime.now(timezone.utc)
date = time.strftime("%a, %d %b %Y %H:%M:%S %Z\r\n", t)

Determining a file's modification time (in seconds since 1 Jan, 1970 on Unix machines)
import os.path
secs = os.path.getmtime(filename)

Convert above time to UTC /GMT (returns a time tuple):
import time
t = time.gmtime(secs)

Convert above time tuple to a string in HTTP format:
last_mod_time = time.strftime("%a, %d %b %Y %H:%M:%S %Z\r\n", t)

Convert a date/time in string format back to time tuple and seconds since 1 Jan, 1970
t = time.strptime(last_mod_time, "%a, %d %b %Y %H:%M:%S %Z\r\n") secs = time.mktime(t)

Submission Guidelines:

Submit the following individual files to Moodle by due date. Please, NO zip files.

- Submit the HTTP client and server source program files (please include full name, UCID (user name), section number in comments at top of source files)

- Submit screenshots in .pdf format showing the output for each test case with your HTTP client (be sure the .pdf is legible)

- Submit a wireshark .pcap file captured while running each of the 3 test cases. A single .pcap file for all 3 test cases is fine. .pcap file names should have the following form: "<user- name>-http-client.pcap", where <user-name> is the NJIT login/email name.

- If you have tested your HTTP Server with a web browser, submit .pdf screenshots and corresponding wireshark trace for all test cases. Name the wireshark trace "<user-name>- web-browser.pcap" to distinguish from above.

- Submit the README file using the submission format on Moodle). Include in your README which test cases are working or not working.

Attachment:- Conditional-Get-Example.rar

Reference no: EM131911151

Questions Cloud

Calculate the overhead assigned to each product : Total estimated overhead costs are $503,250, of which $224,400 is assigned to the material handling cost pool, Calculate the overhead assigned to each product
How you could use social media to network with peers : Write an explanation of how you could use social media to network with peers or professionals in the health field.
What is the amount of each annual payment : If a five-year ordinary annuity has a present value of $1,000, and if the interest rate is 8%, what is the amount of each annual payment?
Review the foods association with the salmonella foodborne : The goal is to review the foods (water or food handlers) association with the following foodborne illness associated pathogens.
Write a simplified version of a http client and server : 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 HTTP GET method.
Calculate jen and berry company break-even point : Fixed advertising costs would increase by $55,600 per year. Calculate Jen & Berry Company's break-even point in number of cases
Describes what we know is effective drug treatment : What can a person do if they experience loss of control of their substance use and the negative impacts on their life?
Explain replacement algorithms for paged system : File are allocated disk space by the operating systems. Explain the three ways of allocating disk space.
Dividend discount model in calculating the wacc : The question asks to use the dividend discount model in calculating the WACC. To determine the DDM Dividend per share

Reviews

Write a Review

Computer Engineering Questions & Answers

  What are the latest ways to steal identity and money

What are the latest ways to steal identity and money? Social Security numbers are the most valuable pieces of consumer information for identity thieves! How can we prepare and protect ourselves?

  Draw a map to illustrate the above data structure

A 68020-based single-board microprocessor system is to be used to keep track of items in a shop. The shop sells up to N items.

  Explain the r-value of the common double-door windows

Consider an ordinary house with R-13 walls (walls that have an R-value of 13 h.ft2.°F/Btu). Compare this to the R-value of the common double-door windows.

  Give declaration and definition of a structure

Write down a program to display the initial values held by the structure (you must use a structure) on the screen.give declaration and definition of a structure.

  How do we find the optimal pair of children

Now consider the case of Kc = 2. How do we find the optimal pair of children? What is the computational complexity of this task?

  What is the average number of machine cycles

What is the average number of machine cycles per instruction for this microprocessor - What is the clock rate (machine cycles per second) required for this microprocessor to be a "1 MIPS" processor?

  What content type in s-mtme provides given security services

What content type in S/MTME provides the following security services: confidentiality, message integrity, authentication and nor repudiation.

  Write a general red-ify function

Write a general red-ify function. Write a function that accepts a picture as input, then doubles red value of every pixel and cut blue and green values in half.

  Describe the four steps of a typical plc processor scan

The actual scan time, or time it takes the PLC to complete a four-step scan, decreases as the number of program words increases.

  Questionwe define the escape problem as follows we are

questionwe define the escape problem as follows. we are given a directed graph g v e picture a network of roads. a

  Create a new image from the process

In this project, we will work on how to find the average color in a larger block of pixels can be thought of as a very simple re-sampling of the bigger image. This technique is often used to generate smaller versions of big images.

  Write a method public static array list merge

Write a method public static Array List merge(Array List a, Array List b) that merges two array lists, alternating elements from both array lists.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd