Next: Request/Response handling
Up: Design
Previous: Design
Since I'll be using non-blocking sytem calls, read() and write() calls to the
sockets are not necessarily completed in each run. Therefore some
sort of state saving structure is needed. A client
object is also needed to store the state information for each active
connection.
I decided to use the general proxy framework Jeremy Gilbert and
Seth Landsman proposed in their design of the web proxy.
The proxy has a total of 17 possible states, described below:
- Start state
- The starting state of the proxy. As soon as the
first client connects to the proxy it leaves that state and never
enters it again. All the proxy does now is loop over the client
object it has created.
- Client accepted
- The client object enters this state after the
remote client has been accepted and all of its variables been set.
- Reading request
- Before reading the remote request, the client
object enters this state.
- Processing request
- After reading the request, the client object enters
this state, where it processes the request, e.g. deciding whether the response
should be sent from the cache or not.
- Connect to server
- In this state, the client object opens a connection
to the remote server.
- Forward request to server
- After opening the connection, the
client object sends the request to the remote host.
- Read response
- In this state the client object reads the response from
the remote host.
- Process response
- After reading the response, various headers are
extracted from it.
- Send response to client
- The response from the remote host is
now forwarded back to the remote client.
- Write to cache
- In this state, the client object writes the response to
the cache.
- Processing cache
- The client object creates a new cache file.
- Finish cache write
- Cache has been written to and all that remains is
to update the hash table which contains the request to cache file mappings.
- Open cache
- If the proxy decides (in the 'Processing request'
state) that the response should be sent from cache, the proxy enters
this state. Here it locates the correct response data to send in cache.
- Send cached data
- After locating the correct response, the cache
sends the cached data to the client.
- Request error
- Error in the request from the client.
- Send error
- Error in the response from the server.
- Client cleanup
- The client is finished. Delete all un-needed data.
Next: Request/Response handling
Up: Design
Previous: Design
Magnus Bjornsson
1998-05-08