CS 455/555 - Intro to Networks and Communications
Fall 2008: Tues/Thurs 3-4:15pm, Dragas 1117

Print - Admin

Announcements

Staff

Schedule

Syllabus (pdf)

Useful Links

Program 3: HTTP/1.0 Proxy Server

Assigned: Thursday, October 16, 2008
Due: Tuesday, November 11, 2008 before class

Description Requirements Rules Testing Helpful Hints Submission

Description

For this assignment, we will be combining the HTTP client and HTTP server written for Program 2 into an HTTP/1.0 proxy server. Remember that a proxy server typically receives a request from a web client, checks its cache, and if the information is not in the cache, passes the request to the web server. The response is returned to the proxy server and is stored in the cache. Finally, the the proxy server returns the response to the client.

Your assignment is to write a simple HTTP/1.0 proxy server that logs the URLs requested, forwards the requests to the server, and forwards the responses to the client. You are not required to actually implement a cache. Remember that non-persistent connections are the default in HTTP/1.0.

Important points from RFC 1945 (HTTP/1.0):

  • "A proxy is a forwarding agent, receiving requests for a URI (MCW: URI is essentially the same thing as URL) in its absolute form, rewriting all or parts of the message, and forwarding the reformatted request toward the server identified by the URI." (Section 1.3)
  • "Proxy and gateway applications must be careful in forwarding requests that are received in a format different than that of the application's native HTTP version. Since the protocol version indicates the protocol capability of the sender, a proxy/gateway must never send a message with a version indicator which is greater than its native version; if a higher version request is received, the proxy/gateway must either downgrade the request version or respond with an error." (Section 3.1) (MCW: Your proxy must downgrade the request version.)
  • "The two options for Request-URI are dependent on the nature of the request. The absoluteURI form is only allowed when the request is being made to a proxy. The proxy is requested to forward the request and return the response." (Section 5.1)

Notes:

  • Do not wait until the last minute to start this assignment. This program builds upon Program 2. If you had trouble with Program 2, please seek help from the TA or instructor and ask questions early.
  • CS 455 students: anything listed as 555-only is not required for you, but will be counted as extra credit if completed.

Requirements

  • Take a port (between 10000-11000) as the only command-line argument. This port is what the server will listen for requests on. If given no command-line argument, print a "Usage" statement and exit.
  • For each new connection, display the client's IP address and port.
  • For each request, write the current date/time, client's IP address and port, and the requested URL to a text file named 'proxy-log.txt' - one request per line.
Example: 10/23/2008 14:53:40 EDT 128.82.5.53 51617 http://www.cs.odu.edu/~mweigle/
  • Print the request header received from the client.
  • Modify the request as needed. Your proxy server should not send any request header fields that do not start with "Accept", "Cookie", "Host", or "User-Agent".
  • Print the modified request header that is sent to the server.
  • Print the response header received from the server.
  • Your proxy server must keep processing requests until the user quits the program with Ctrl-C.
  • Your proxy server must manage connections according to the default specifications for HTTP/1.0.
  • Your source file must be named HTTPProxyServer.java
  • 555-only: Your proxy server must handle all types of requests and responses, including those for images, PDFs, etc.
  • 555-only: Write the answers to the following questions in a file named Prog3.txt and submit it with your source code:
    1. Request a URL with your HTTP client from Program 2. What was the response time?
    2. Modify your HTTP client from Program 2 to use your proxy server (send the request with the full URL in the GET line and connect to the proxy server instead of the web server). Request the same URL as above using the proxy server. What was the response time?
    3. Were these response times different? If so, why?

Rules

  • As with all projects, you are not permitted to work with anyone else (even students not in the class) - all of the coding and documentation must be your own.
  • Your program must compile and run on the CS Unix machines.
  • You must just use basic socket communication (send strings over the socket) to communicate with the server. You are not allowed to use any of Java's URL or HTTP classes.
  • You are not required to handle the following exceptions:
    • Exception in thread "main" java.net.ConnectException: Connection refused - when asking to connect to a host and port that aren't listening
    • Exception in thread "main" java.net.SocketException: Broken pipe - when the client unexpectedly dies

Testing

  • Your program will be graded on how well it satisfies the requirements in handling a set of test URLs. You should test your programs rigorously before submitting.
  • Any web browser should be able to talk to your proxy server once you change the proxy settings. (Do not change proxy settings on lab machines!)
    • If you do not have access to something other than a lab machine, modify your HTTPClient from Program 2 to use your proxy server (send the request with the full URL in the GET line and connect to the proxy server instead of the web server).
  • Your proxy server should be able to talk to your HTTPServer from Program 2.

Helpful Hints

  • Make sure that your URL parser can handle URLs that contain special characters (including ':') in the path.
For example: http://sb.google.com/safebrowsing/update?client=navclient-auto-ffox&appver=2.0.0.7&version=goog-white-domain:1:23
  • Flush the output file (proxy-log.txt) after each write. You can also setup PrintWriter to automatically flush the file.
  • readLineBytes is a helper method that you may use in your program. It takes a DataInputStream object as a parameter and returns a String. This will allow you to read from the socket one line at a time just like readLine(), but it will not corrupt binary data (MCW 10/20/08 - not true - readLineBytes() will corrupt binary data). Note that just like readLine(), it will strip off the "\r\n" from text lines.
  • Note that the location of the proxy server is not included in the URL. It is something that has to be setup in the configuration of the client.

Submission

You must name your HTTP proxy server source file HTTPProxyServer.java. Make sure that you submit all files necessary to compile your program, but do not submit the .class files.

555-only: Also submit your modified HTTPClient.java and Prog3.txt.

Directions for submitting your assignment through Blackboard