com.flat502.rox.http
Class HttpRequestBuffer

java.lang.Object
  extended by com.flat502.rox.http.HttpMessageBuffer
      extended by com.flat502.rox.http.HttpRequestBuffer

public class HttpRequestBuffer
extends HttpMessageBuffer

This class represents a buffer built up from one or more network messages, and containing an HTTP request.


Constructor Summary
HttpRequestBuffer(HttpRpcServer server, java.net.Socket socket)
           
HttpRequestBuffer(HttpRpcServer server, java.net.Socket socket, EncodingMap encodingMap)
          Construct a new buffer for requests on the given socket.
 
Method Summary
 java.util.Map getAcceptedEncodings()
          Return a list of acceptable encodings (as specified by the client).
 Encoding getContentEncoding()
           
 java.io.InputStream getContentStream()
           
 double getHttpVersion()
           
 java.lang.String getHttpVersionString()
           
 java.lang.String getMethod()
           
 java.lang.String getURI()
           
 boolean isComplete()
          Test if this buffer contains a complete HTTP message.
 java.lang.String toString()
           
protected  void unpackPreamble(java.lang.String line)
           
protected  void validateHeaders()
           
 
Methods inherited from class com.flat502.rox.http.HttpMessageBuffer
addBytes, getContent, getContentCharset, getContentReader, getContentType, getHeaders, getHeaderValue, getOrigin, getSocket, normalizeHeaderName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HttpRequestBuffer

public HttpRequestBuffer(HttpRpcServer server,
                         java.net.Socket socket)

HttpRequestBuffer

public HttpRequestBuffer(HttpRpcServer server,
                         java.net.Socket socket,
                         EncodingMap encodingMap)
Construct a new buffer for requests on the given socket.

Parameters:
server -
socket - The socket from which data for this buffer will be gathered.
encodingMap - An EncodingMap for mapping Content-Encoding header values to an appropriate Encoding. May be null.
Method Detail

getMethod

public java.lang.String getMethod()

getURI

public java.lang.String getURI()

isComplete

public boolean isComplete()
                   throws java.lang.Exception
Description copied from class: HttpMessageBuffer
Test if this buffer contains a complete HTTP message.

Roughly speaking this test consists of three steps, ordered as follows:

  1. A test if a complete set of HTTP headers are present.
  2. A test if the Content-Length header is present.
  3. A test if the Content-Length header value and the content of the HTTP message are equal.

Overrides:
isComplete in class HttpMessageBuffer
Returns:
true if this buffer holds a complete HTTP message, otherwise false.
Throws:
java.lang.Exception - if a problem occurs applying any of the tests mention above.

getAcceptedEncodings

public java.util.Map getAcceptedEncodings()
Return a list of acceptable encodings (as specified by the client).

The Accept-Content header is interpreted as per section 14.3 of RFC 2616 are stripped off and excluded from the return values.

The returned map uses String keys specifying the encoding names (converted to lowercase) and Float values specifying the qvalue. If no qvalue was specified a null value is used (which should be interpreted as an implicit value "1.0"). If duplicate encodings are specified the highest q-value will be retained. An unspecified q-value is treated as having a higher value than an explicit value of "1.0".

An empty Accept-Content header will return an empty map.

Iterating over the key-set of the map returned is guaranteed to return the encodings ordered in descending order of qvalue. Ties (i.e. equal qvalues) are broken by sorted so the first to appear in the header value appears first.

The map instance returned is unmodifiable.

Returns:
null if no Accept-Encoding header was present, or a map of accepted encodings.

getContentEncoding

public Encoding getContentEncoding()

getContentStream

public java.io.InputStream getContentStream()
                                     throws java.io.IOException
Overrides:
getContentStream in class HttpMessageBuffer
Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class HttpMessageBuffer

unpackPreamble

protected void unpackPreamble(java.lang.String line)
                       throws HttpResponseException
Specified by:
unpackPreamble in class HttpMessageBuffer
Throws:
HttpResponseException

getHttpVersion

public double getHttpVersion()
Specified by:
getHttpVersion in class HttpMessageBuffer

getHttpVersionString

public java.lang.String getHttpVersionString()
Specified by:
getHttpVersionString in class HttpMessageBuffer

validateHeaders

protected void validateHeaders()
                        throws HttpBufferException
Overrides:
validateHeaders in class HttpMessageBuffer
Throws:
HttpBufferException