CIS4307 - Homeworks 3: A concurrent HTTP Server with CGI

Given: October 20, 2009
Due Date: November 9, 2009, by 10pm

Your homework will consist of three programs:

  1. A modified multi threaded version of the web server Tiny that I will give to you
  2. A program that will be executed as a CGI request. This program, say txt2html, given the name of a text file, will produce an HTML page containing the text of that file with appropriate tags [at least <html>, <body>, and <pre>].
  3. A multi threaded client used to request pages from the server.

Here is a pointer to all the code you need for this homework.
The "tiny" web server is minimally modified from http://csapp.cs.cmu.edu. The server fetches pages ONLY from the directory in which it is executing and in directories below it. This server can execute cgi-bin programs. It is very nice and useful code that can give you ideas on socket programming and on HTTP. You are to read and understand little by little all this code.
You are to modify the code provided (mark each of your sections starting with /*vvCIS4307xyzvv*/ and ending with /*^^CIS4307xyz^^*/) (where c4307xyz is your account) as follows:

You will launch your program, if your account is c4307214, as follows: lab3 37214 &
where 37214 is the port where your server will wait for requests.

In the directory where you run your program place 3 small HTML files, file1.html, file2.html, file3.html. They must be publicly readable. In the subdirectory cgi-bin place the program txt2html and a text file, say file1.txt. This directory must be universally readable and executable. The program txt2html must be universally executable and file1.txt must be universally readable.

From a browser, if your server is moo.cis.temple.edu, you will use urls like

 
   http://moo.cis.temple.edu:37214/file1.html
   http://moo.cis.temple.edu:37214/file2.html
   http://moo.cis.temple.edu:37214/file3.html
   http://moo.cis.temple.edu:37214/cgi-bin/txt2html?file1.txt
Processing of cgi-bin requests, as always will involve a fork and an exec call. Tiny passes parameters to the cgi program by using an environment variable.

The multithreaded client will have a number (say 4) of thread each independently requesting pages from the server [the requests are at each iteration chosen randomly among the possible requests]. Each thread will just read and discard the response, but will remember the time when it made the request and the time when it completed the response. Then every one hundred requests will print the average response time to the screen.

Remember to protect all your program files - otherwise they will become readable on the web.

Submit the homework to the blackboard dropbox.