COSC 4377 - Introduction to Computer NetworksSpring 2012MW 1:00-2:30pm at PGH347
Homework 2 : HTTP ClientDue: midnight February 1, 2012In this assignment, we will write an HTTP client. We will write a program that can download files from the web using the HTTP protocol. Our HTTP client should be able to download text and binary data. The user specifies the URL to the file to be downloaded as a command line argument. Here is how we might use the tool: ./http_client -u url -o output_file Example: ./http_cient -u http://www2.cs.uh.edu/~gnawali/courses/cosc4377-s12/hw2/test1.txt -o mytest1.txtIn the example above, the user wanted to download the test1.txt file at the speified URL and save the content to mytest1.txt. Implementation GuideWeb servers accept requests using a protocol called HTTP. When we type a URL into a web browser, the request to the web server is sent using the HTTP protocol. The program that you write in this assignment will pretend to be a web browser and send an HTTP request to the web server.When the program is launched from the command line, open a socket to the server and write a valid HTTP request on that socket. The server will respond with an HTTP response. You can read that response using the same socket. An HTTP response has certain message format. You need to parse that message correctly, otherwise we won't know where the message begins or ends. It is helpful for debugging if you printf all the inbound and outbound messages. You are not allowed to use any http/curl/file download libraries for this assignment because our goal is to learn how to read and write valid HTTP messages.
Testing your programWe will test your program by computing the difference between the file saved by your program and the file in the original URL. Here is how to do it. Downloads the test files using a browser. Download those test files the second time using your program. If your program is downloading the files correctly, there should be no difference between the two downloads (using the browser and your program). You might want to use the command called "diff" in Linux to check if the files are different. We are providing five test cases:
It is not necessary for your program to work with redirects, persistent connections, etc. If it can download and save static files using HTTP 1.0 that is good enough. We have packaged all these test cases into a single tarball, which you can download at this link: http://www2.cs.uh.edu/~gnawali/courses/cosc4377-s12/hw2/testfiles.tar.gz In the tarball, you will also find grade.sh, which will test your code against the first 9 test cases and tell you your grade out of 90. We will test the last case manually. HTTPOur HTTP client will use the most basic parts of HTTP version 1.0. RFC 1945 describes the protocol. You need to find what the http header fields are, their correct values, and how to interpret them. Here is one reference that gives an overview of HTTP [local copy].
|