The first step is implementing a basic logging proxy. When started,
your proxy should open a socket and listen for connections. When it
gets a connection (from a browser), it should accept the connection,
read the request, check if the address is blocked, and parse it to
determine the server that the request was meant for. It should then
open a socket connection to that server, send it the request, receive
the reply, and forward the reply to the browser if the request is not
blocked.
Notice that, since your proxy is a middleman between client and
server, it will have elements of both. It will act as a server to the
web browser, and as a client to the web server. Thus you will get
experience with both client and server programming.
To do this part, you will need to understand socket programming and
basic HTTP. See Resources section below for help on
these topics.
Filtering
The blocked URLs are stored in proxy.filter. The web proxy may
read in the addresses at the initialization. When a request on a
blocked address comes from a web browser, the proxy should return a
permission denied information to the browser in the following
format:
<html><head><title>Proxy error>/title></head>
<body>You are not allowed to access this web page.</body></html>
Logging
Your proxy should also keep track of all requests in a log file named
proxy.log. Each line should be of the form:
Date: browserIP URL size
where browserIP is the IP address of the browser, URL is the
URL asked for, size is the size in bytes of the object that was
returned. For instance:
Fri 13 Apr 2001 02:51:02 EST: 128.2.111.38 http://www.cs.cmu.edu/ 34314
Note that size is essentially the number of bytes received from
the server, from the time the connection is opened to the time it is
closed. Only requests that are met by a response from a server (or
cached response) should be logged. We have provided the function
void format_log_entry() to create a log entry in the required
format.
Port Numbers
Since there will be many people working on the same machine, all of
you can not use the same port to run your proxies. You are allowed to
select any non-privileged port for your proxy, as long as it is not
taken by other system processes. Selecting a port in the upper
thousands is suggested (i.e., 3070 or 8104).