rabbit.proxy
Class Connection

java.lang.Object
  extended by rabbit.proxy.Connection

public class Connection
extends Object

The base connection class for rabbit. This is the class that handle the http protocoll for proxies.

Author:
Robert Olofsson

Constructor Summary
Connection(ConnectionId id, SocketChannel channel, Selector selector, HttpProxy proxy, BufferHandler bufHandler)
           
 
Method Summary
 void doError(int statuscode, Exception e)
          Send an error (400 Bad Request or 504) to the client.
 void doError(int status, String message)
          Send an error (400 Bad Request) to the client.
 BufferHandler getBufferHandler()
           
 SocketChannel getChannel()
           
 boolean getChunking()
          Get the chunking option.
 String getContentLength()
           
 Counter getCounter()
           
 String getExtraInfo()
           
 HttpGenerator getHttpGenerator()
           
 ConnectionId getId()
           
 boolean getKeepalive()
          Get the keepalive value.
 Logger getLogger()
           
 boolean getMayCache()
          Get the state of this request.
 boolean getMayFilter()
          Get the state of the request.
 boolean getMayUseCache()
          Get the state of this request.
 boolean getMeta()
          Get the state of this request.
 String getPassword()
           
 HttpProxy getProxy()
           
 String getRequestLine()
           
 String getRequestVersion()
          Get the http version that the client used.
 Selector getSelector()
           
 long getStarted()
          Get the time this connection was started.
 String getStatus()
           
 String getStatusCode()
           
 String getUserName()
           
 void handleMeta()
          Handle a meta page.
 void handleRequest()
          Handle a request by getting the datastream (from the cache or the web).
 void logAndClose(rabbit.proxy.Connection.RequestHandler rh)
           
 void logAndRestart()
           
protected  boolean mustTunnel(rabbit.proxy.Connection.RequestHandler rh)
          Check if we must tunnel a request.
 void readRequest()
          Read a request.
 void setChunking(boolean b)
          Set the chunking option.
 void setContentLength(String contentLength)
          Set the content length of the response.
 void setExtraInfo(String info)
          Set the extra info.
 void setKeepalive(boolean keepalive)
          Set keepalive to a new value.
 void setMayCache(boolean cacheAllowed)
          Set the state of this request.
 void setMayFilter(boolean filterAllowed)
          Get the state of this request.
 void setMayUseCache(boolean useCache)
          Set the state of this request.
 void setMeta(boolean meta)
          Set the state of this request.
 void setMustRevalidate(boolean b)
           
 void setPassword(String password)
           
 void setStatusCode(String statusCode)
           
 void setUserName(String userName)
           
 boolean useFullURI()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Connection

public Connection(ConnectionId id,
                  SocketChannel channel,
                  Selector selector,
                  HttpProxy proxy,
                  BufferHandler bufHandler)
Method Detail

getId

public ConnectionId getId()

readRequest

public void readRequest()
Read a request.


handleMeta

public void handleMeta()
Handle a meta page.


handleRequest

public void handleRequest()
Handle a request by getting the datastream (from the cache or the web). After getting the handler for the mimetype, send it.


mustTunnel

protected boolean mustTunnel(rabbit.proxy.Connection.RequestHandler rh)
Check if we must tunnel a request. Currently will only check if the Authorization starts with NTLM or Negotiate.

Parameters:
rh - the request handler.

doError

public void doError(int status,
                    String message)
Send an error (400 Bad Request) to the client.

Parameters:
status - the status code of the error.
message - the error message to tell the client.

doError

public void doError(int statuscode,
                    Exception e)
Send an error (400 Bad Request or 504) to the client.

Parameters:
statuscode - the status code of the error.
e - the exception to tell the client.

getChannel

public SocketChannel getChannel()

getSelector

public Selector getSelector()

getProxy

public HttpProxy getProxy()

getBufferHandler

public BufferHandler getBufferHandler()

getLogger

public Logger getLogger()

getCounter

public Counter getCounter()

setKeepalive

public void setKeepalive(boolean keepalive)
Set keepalive to a new value. Note that keepalive can only be promoted down.

Parameters:
keepalive - the new keepalive value.

getKeepalive

public boolean getKeepalive()
Get the keepalive value.

Returns:
true if keepalive should be done, false otherwise.

getUserName

public String getUserName()

setUserName

public void setUserName(String userName)

getPassword

public String getPassword()

setPassword

public void setPassword(String password)

getRequestLine

public String getRequestLine()

getRequestVersion

public String getRequestVersion()
Get the http version that the client used. We modify the request header to hold HTTP/1.1 since that is what rabbit uses, but the real client may have sent a 1.0 header.


getStatus

public String getStatus()

getStatusCode

public String getStatusCode()

getContentLength

public String getContentLength()

getExtraInfo

public String getExtraInfo()

setExtraInfo

public void setExtraInfo(String info)
Set the extra info.

Parameters:
info - the new info.

getStarted

public long getStarted()
Get the time this connection was started.


setChunking

public void setChunking(boolean b)
Set the chunking option.

Parameters:
b - if true this connection should use chunking.

getChunking

public boolean getChunking()
Get the chunking option.

Returns:
if this connection is using chunking.

getMeta

public boolean getMeta()
Get the state of this request.

Returns:
true if this is a metapage request, false otherwise.

setMeta

public void setMeta(boolean meta)
Set the state of this request.

Parameters:
meta - true if this request is a metapage request, false otherwise.

setMayUseCache

public void setMayUseCache(boolean useCache)
Set the state of this request. This can only be promoted down..

Parameters:
useCache - true if we may use the cache for this request, false otherwise.

getMayUseCache

public boolean getMayUseCache()
Get the state of this request.

Returns:
true if we may use the cache for this request, false otherwise.

setMayCache

public void setMayCache(boolean cacheAllowed)
Set the state of this request. This can only be promoted down.

Parameters:
cacheAllowed - true if we may cache the response, false otherwise.

getMayCache

public boolean getMayCache()
Get the state of this request.

Returns:
true if we may cache the response, false otherwise.

setMayFilter

public void setMayFilter(boolean filterAllowed)
Get the state of this request. This can only be promoted down.

Parameters:
filterAllowed - true if we may filter the response, false otherwise.

getMayFilter

public boolean getMayFilter()
Get the state of the request.

Returns:
true if we may filter the response, false otherwise.

setMustRevalidate

public void setMustRevalidate(boolean b)

setContentLength

public void setContentLength(String contentLength)
Set the content length of the response.

Parameters:
contentLength - the new content length.

setStatusCode

public void setStatusCode(String statusCode)

useFullURI

public boolean useFullURI()

logAndClose

public void logAndClose(rabbit.proxy.Connection.RequestHandler rh)

logAndRestart

public void logAndRestart()

getHttpGenerator

public HttpGenerator getHttpGenerator()