COMP 361 Course Project : A Multi-Threaded Proxy Server

In this programming assignment we will develop a dummy proxy server. In the end, you will have built a multi-threaded proxy server that is capable of processing multiple simultaneous service requests in parallel. You should be able to demonstrate that your proxy server is capable of retrieving and delivering simple web pages to a Web browser.

We are going to implement part of version 1.1 of HTTP, as defined in RFC 2616 , where separate HTTP requests are sent for each component of the Web page. The server will be able to handle multiple simultaneous service requests in parallel. This means that the Web server is multi-threaded. In the main thread, the server listens to a fixed port. When it receives a TCP connection request, it sets up a TCP connection through another port and services the request in a separate thread.

As you are developing the code, you can test your server from a Web browser. But remember that you need to configure your Web browser to use your proxy server. For example, if you are using netscape7, you need to specify the host name and port number of your proxy server manually by going through the menu [Edit->Preferences->Advanced->Proxies], and type the required information in the HTTP proxy preference box.

Proxy Server Requirement

In this assignment, you only implement part of the HTTP version 1.1.
Here are the guidelines  you should follow:

  1. Only GET and HEAD requests are served.
  2. Caching needs NOT to be implemented.
  3. The server must NOT forward the Connection, Proxy-Connection, Keep-Alive, If-Modified-Since and If-None-Match Headers.
  4. The server must support If-Modified-Since conditional requests.
  5. The server must implement HTTP code 304, 501, 502 correctly.
  6. The server can run on JDK 1.4 or later.

For the details of the above requirements, you are advised to read RFC 2616 carefully.

The Code

The program consists of two classes:

ProxyServer
HttpRequest

You need to complete the code in both ProxyServer class and HttpRequest.

The places where you need to complete the code have been marked with the comments /* Fill in */. Each of the places requires one or more lines of code.

The ProxyServer relays HTTP requests that it receives through a well-known port number 3128 or 8080. You can choose any port higher than 1024, but make sure that the same port number is used in the HTTP proxy setting of your browser. Each time the ProxyServer receives an HTTP connection, it calls the multi-threaded class HttpRequest and passes the HTTP connection to it for handling the actual request. The HttpRequest thread processes the request by connecting to the destination Web server, retrieving the content corresponding to the request, and forwarding to the Web browser. After the class HttpRequest completes the HTTP request, it closes the connections of both the destination Web server and the Web browser.

Hints

To simplify the debugging process, you are advised to write the code in phases. First you should implement the HTTP proxy server to relay simple and valid requests, and then implement the "If-Modified-Since" and invalid request requirements for the server. To test the proxy server during  the first phase, you can request a simple web page that consists only of simple sentence and several images. You also need to check the server correctness in handling invalid requests such as "bad gateway" and "method not implemented".