CS 43 Lab 1: A Basic Web Client

Due: Thursday, September 14, 11:59 PM

Handy References:

Lab Audio

Lab 1 Goals:


For this week's programming exercise, we will create a barebones web client (think wget). Based on the example TCP client code in your repository and the HTTP example sessions shown in class, we'll write a command-line program called lab1 that takes a URL as its only parameter, retrieves the indicated file, and stores it in the local directory with the appropriate filename. If the URL does not end in a filename, your program should automatically name the file 'index.html'.

For example:

# This should create a local file named 'pride_and_prejudice.txt' containing lots of text.
 $ ./lab1 http://demo.cs.swarthmore.edu/example/pride_and_prejudice.txt

# This should create a local file named 'index.html' containing the demo server's home page contents.
 $ ./lab1 http://demo.cs.swarthmore.edu

# This should create a local image file named 'fiona.jpg' containing a cute cat picture.
 $ ./lab1 http://demo.cs.swarthmore.edu/example/fiona.jpg

You may assume that the URL will be no more than 100 characters long and that it will be of the form http://host/path, where:

You may assume that the files you'll be retrieving are no larger than one megabyte. This means you can statically declare storage space for the response, which makes life a bit easier.


Miscellaneous hints and background information


To test your program, you'll want to ensure that the files it's saving are identical to the originals.

For a quick check, you can open the file in a browser, and it should appear like the original website. Note that appearance alone does NOT guarantee that the file is byte-for-byte identical.

An easy and more precise way to check that the files are correct is to use wget, which downloads files much like your lab program, to retrieve a correct copy of the file. You can then compare wget's file with yours.

For text files, you can use diff to see if the files are identical. For all files (text and binary) you can use something like md5sum to generate a hash of the two files. If the hashes differ, so do the files.


Please remove any debugging output prior to submitting.

To submit your code, simply commit your changes locally using git add and git commit. Then run git push while in your lab directory.