|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.flat502.rox.http.HttpMessageBuffer
public abstract class HttpMessageBuffer
Abstract base class for a buffer built up from one or more network messages, and containing an HTTP message.
Constructor Summary | |
---|---|
protected |
HttpMessageBuffer(HttpRpcProcessor processor,
java.net.Socket socket)
Construct a new buffer for the given socket. |
Method Summary | |
---|---|
int |
addBytes(byte[] newData,
int offset,
int count)
Add new data received on the socket this buffer is associated with. |
byte[] |
getContent()
|
java.nio.charset.Charset |
getContentCharset()
|
java.io.Reader |
getContentReader()
|
java.io.InputStream |
getContentStream()
|
java.lang.String |
getContentType()
Get Content-Type defined in this message. |
java.util.Map<java.lang.String,java.lang.String> |
getHeaders()
Provides access to the headers in the underlying HTTP message. |
java.lang.String |
getHeaderValue(java.lang.String name)
|
abstract double |
getHttpVersion()
|
abstract java.lang.String |
getHttpVersionString()
|
HttpRpcProcessor |
getOrigin()
|
java.net.Socket |
getSocket()
Get the socket data for this buffer was collected from. |
boolean |
isComplete()
Test if this buffer contains a complete HTTP message. |
protected java.lang.String |
normalizeHeaderName(java.lang.String name)
Called to normalize header names. |
java.lang.String |
toString()
|
protected abstract void |
unpackPreamble(java.lang.String line)
|
protected void |
validateHeaders()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected HttpMessageBuffer(HttpRpcProcessor processor, java.net.Socket socket)
processor
- socket
- The socket from which data for this buffer will be
gathered.Method Detail |
---|
public java.net.Socket getSocket()
public HttpRpcProcessor getOrigin()
public int addBytes(byte[] newData, int offset, int count) throws java.lang.Exception
This method gathers message fragments together.
A call to this method is typically followed by a
call to isComplete()
to determine whether
or not the buffer contains a complete HTTP message.
newData
- The data to add to this buffer.offset
- The offset within newData
to begin
copying from.count
- The number of bytes from newData
to
copy.
-1
if the message is incomplete, 0
if it is complete and
a positive integer if the message is complete and additional data remains
in the input buffer. In the latter case the returned value is the index
into newData at which the excess data begins.
java.lang.Exception
- for the same reasons described under isComplete()
.public boolean isComplete() throws java.lang.Exception
Roughly speaking this test consists of three steps, ordered as follows:
Content-Length
header is present.Content-Length
header value and the
content of the HTTP message are equal.
true
if this buffer holds a complete HTTP message,
otherwise false
.
java.lang.Exception
- if a problem occurs applying any of the tests mention above.public java.util.Map<java.lang.String,java.lang.String> getHeaders()
This method returns an unmodifiable Map
containing the headers in the underlying HTTP
message. This map's key set iterator will return
the keys in the order in which they appeared in the
request.
Duplicate headers will have been combined into a single value as per section 4.2 of RFC 2616.
Map
containing the
headers in the underlying HTTP message.
java.lang.IllegalStateException
- if this request is not yet complete.public java.lang.String getHeaderValue(java.lang.String name)
public byte[] getContent()
public java.io.InputStream getContentStream() throws java.io.IOException
java.io.IOException
public java.io.Reader getContentReader() throws java.io.IOException
java.io.IOException
public java.lang.String getContentType()
Content-Type
defined in this message.
Content-Type
or null
if it
is not specified.public java.nio.charset.Charset getContentCharset()
public java.lang.String toString()
toString
in class java.lang.Object
protected abstract void unpackPreamble(java.lang.String line) throws java.lang.Exception
java.lang.Exception
public abstract double getHttpVersion()
public abstract java.lang.String getHttpVersionString()
protected void validateHeaders() throws HttpBufferException
HttpBufferException
protected java.lang.String normalizeHeaderName(java.lang.String name)
This is somewhat cosmetic in that it is used to
ensure consistent access to the underlying Map
of headers without producing headers that are unappealing.
Most documentation uses headers like "Content-Type" and this
method aims to ensure that headers are formatted using this
"convention.
The header name is normalized as though the value were converted to lowercase split on the '-' character, the first letter of each item in the resulting list capitalized, and the updated list rejoined using the '-' as a separator.
name
- The header name to normalize.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |