| java.lang.Object org.jicarilla.http.HTTPParserImpl
HTTPParserImpl | public class HTTPParserImpl implements HTTPParser(Code) | | A component that understands HTTP. Fires off events to a
handler similarly to the way SAX works. Is *not* threadsafe.
The most common state machine failures are:
- AssertionError if an expected LF doesn't follow on CR
- 413 if buffer exceeds MAX_BUFFER_SIZE (for some message parts
only)
- 400 if a byte is encountered that is not acceptable for the current
part of a message.
author: Leo Simons version: $Id: HTTPParserImpl.java,v 1.10 2004/04/03 10:13:24 lsimons Exp $ |
Inner Class :final protected class Context | |
DONE | final public static int DONE(Code) | |
Description:
Alias for
NOT_STARTED .
|
INVALID | final public static int INVALID(Code) | |
Description:
An internal error exists somewhere. Unused.
Next state:
Not applicable.
|
LOOKING_FOR_BODY | final public static int LOOKING_FOR_BODY(Code) | |
Description:
Decide whether there is a body. This is not actually in use as
a state, but rather a special function is called from other
states which are said to change into this one. This function
decides what to look for by querying the handler using
getBodyType().
Next state:
-
DONE , if there is no body.
-
LOOKING_FOR_CHUNKED_BODY , if a body with chunked
transfer-coding is coming.
-
LOOKING_FOR_NORMAL_BODY_UP_TO_SIZE , if a body without
transfer-coding (or with an unknown transfer-coding) is coming.
|
LOOKING_FOR_CHUNKED_BODY | final public static int LOOKING_FOR_CHUNKED_BODY(Code) | |
Description:
Preparing for a body with chunked transfer coding.
Next state:
-
LOOKING_FOR_CHUNKED_BODY_CHUNK_SIZE , always.
|
LOOKING_FOR_CHUNKED_BODY_CHUNK_CONTENTS | final public static int LOOKING_FOR_CHUNKED_BODY_CHUNK_CONTENTS(Code) | |
Description:
Accumulate the current chunk up to its specified size.
Next state:
-
LOOKING_FOR_CHUNKED_BODY_CHUNK_CONTENTS , if the whole
chunk hasn't been read yet.
-
LOOKING_FOR_CHUNKED_BODY_CHUNK_SIZE , if the whole
chunk has been read.
before: send foundBody().
|
LOOKING_FOR_CHUNKED_BODY_CHUNK_SIZE | final public static int LOOKING_FOR_CHUNKED_BODY_CHUNK_SIZE(Code) | |
Description:
Accumulate the hex size of the current chunk.
Next state:
-
LOOKING_FOR_CHUNKED_BODY_CHUNK_SIZE , if the field is not
complete yet.
-
LOOKING_FOR_CHUNKED_BODY_CHUNK_CONTENTS , if CR is
encountered and the size is not 0.
-
LOOKING_FOR_TRAILER , if CR is
encountered and the size is 0.
|
LOOKING_FOR_FIELD1 | final public static int LOOKING_FOR_FIELD1(Code) | |
Description:
Accumulating the first start line field of the message.
Next state:
-
LOOKING_FOR_FIELD1 , if the field hasn't ended yet.
-
LOOKING_FOR_FIELD2 , if SP is encountered.
before: send foundStartLineFirstField().
|
LOOKING_FOR_FIELD2 | final public static int LOOKING_FOR_FIELD2(Code) | |
Description:
Accumulating the second start line field of the message.
Next state:
-
LOOKING_FOR_FIELD2 , if the field hasn't ended yet.
-
LOOKING_FOR_FIELD3 , if SP is encountered.
before: send foundStartLineSecondField().
|
LOOKING_FOR_FIELD3 | final public static int LOOKING_FOR_FIELD3(Code) | |
Description:
Accumulating the third start line field of the message.
Next state:
-
LOOKING_FOR_FIELD3 , if the field hasn't ended yet.
-
LOOKING_FOR_NEW_HEADER , if CR is encountered.
before: send foundStartLineThirdField().
|
LOOKING_FOR_HEADER_NAME | final public static int LOOKING_FOR_HEADER_NAME(Code) | |
Description:
Accumulating the name of the current header.
Next state:
-
LOOKING_FOR_HEADER_NAME , if the name hasn't finished yet.
-
SKIPPING_WHITESPACE_AFTER_HEADER_NAME , if COLON is
encountered.
before: send foundHeaderName().
|
LOOKING_FOR_HEADER_VALUE | final public static int LOOKING_FOR_HEADER_VALUE(Code) | |
Description:
Accumulating the value of the current header.
Next state:
-
LOOKING_FOR_HEADER_VALUE , if the header value hasn't ended
yet.
-
LOOKING_FOR_HEADER_VALUE_OR_NEXT_HEADER , if CR is
encountered.
|
LOOKING_FOR_HEADER_VALUE_OR_NEXT_HEADER | final public static int LOOKING_FOR_HEADER_VALUE_OR_NEXT_HEADER(Code) | |
Description:
Decide whether a header value is complete or whether it is continued
on the next line.
Next state:
-
SKIPPING_HEADER_VALUE_WHITESPACE , if a SP is encountered.
-
LOOKING_FOR_BODY , if a CR is encountered.
before: send foundHeaderValue().
-
LOOKING_FOR_HEADER_NAME , if another header is coming.
before: send foundHeaderValue().
|
LOOKING_FOR_NEW_HEADER | final public static int LOOKING_FOR_NEW_HEADER(Code) | |
Description:
Deciding on state change to new header or body.
Next state:
-
LOOKING_FOR_HEADER_NAME , if a header is coming.
-
LOOKING_FOR_BODY , if CR is encountered.
|
LOOKING_FOR_NORMAL_BODY | final public static int LOOKING_FOR_NORMAL_BODY(Code) | |
Description:
Preparing for a body for which no size is known yet.
Next state:
-
LOOKING_FOR_NORMAL_BODY_UP_TO_SIZE , if the handler can
provide the expected size for the body.
Failure:
- 411 if the handler cannot produce an expected size for the body.
|
LOOKING_FOR_NORMAL_BODY_UP_TO_SIZE | final public static int LOOKING_FOR_NORMAL_BODY_UP_TO_SIZE(Code) | |
Description:
Accumulating the body up to its specified size.
Next state:
-
LOOKING_FOR_NORMAL_BODY_UP_TO_SIZE , if the whole body has
not been read yet.
-
DONE , if the whole body has been read.
before: send foundBody().
before: send endMessage().
|
LOOKING_FOR_NO_BODY | final public static int LOOKING_FOR_NO_BODY(Code) | |
Description:
There is no body to look for. This is not actually in use as
a state, but is included purely to make behaviour of the body
type selection clearer and consistent with getBodyType()
contracts.
Next state:
not applicable.
|
LOOKING_FOR_TRAILER | final public static int LOOKING_FOR_TRAILER(Code) | |
Description:
Decide whether a trailer is coming by calling hasTrailers() on
the handler.
Next state:
-
LOOKING_FOR_TRAILER_NAME , if trailers are coming.
-
DONE , if no trailers are coming.
before: send endMessage().
|
LOOKING_FOR_TRAILER_NAME | final public static int LOOKING_FOR_TRAILER_NAME(Code) | |
Description:
Accumulating the name of the current trailer.
Next state:
-
LOOKING_FOR_TRAILER_NAME , if the trailer hasn't finished
yet.
-
SKIPPING_WHITESPACE_AFTER_TRAILER_NAME , if COLON is
encountered.
before: send foundFooterName().
|
LOOKING_FOR_TRAILER_VALUE | final public static int LOOKING_FOR_TRAILER_VALUE(Code) | |
Description:
Accumulating the value of the current trailer.
Next state:
-
LOOKING_FOR_HEADER_VALUE , if the trailer value hasn't ended
yet.
-
LOOKING_FOR_HEADER_VALUE_OR_NEXT_HEADER , if CR is
encountered.
|
LOOKING_FOR_TRAILER_VALUE_OR_NEXT_TRAILER | final public static int LOOKING_FOR_TRAILER_VALUE_OR_NEXT_TRAILER(Code) | |
Description:
Decide whether a trailer value is complete or whether it is continued
on the next line.
Next state:
-
SKIPPING_HEADER_VALUE_WHITESPACE , if a SP is encountered.
-
LOOKING_FOR_BODY , if a CR is encountered.
before: send foundTrailerValue().
-
LOOKING_FOR_HEADER_NAME , if another header is coming.
before: send foundTrailerValue().
|
MAX_BUFFER_SIZE | final public static int MAX_BUFFER_SIZE(Code) | | If the current view buffer exceeds this value,
we throw an HTTP Exception. This prevents us from
hanging on really big requests. (10kb worth of
buffer should be plenty)
|
NOT_STARTED | final public static int NOT_STARTED(Code) | |
Description:
Haven't read a single byte yet of the upcoming message.
Next state:
-
SKIPPING_HEADER_NEWLINES , always.
before: send newMessage().
|
SKIPPING_HEADER_NEWLINES | final public static int SKIPPING_HEADER_NEWLINES(Code) | |
Description:
Ignoring CRLF sequences before the start of the message.
Next state:
-
SKIPPING_HEADER_NEWLINES , if there's more CRLF.
-
LOOKING_FOR_FIELD1 , if there's anything else.
|
SKIPPING_HEADER_VALUE_WHITESPACE | final public static int SKIPPING_HEADER_VALUE_WHITESPACE(Code) | |
Description:
Ignoring the continuation whitespace in a multiline header.
Next state:
-
SKIPPING_HEADER_VALUE_WHITESPACE , if SP or HT is
encountered.
-
LOOKING_FOR_HEADER_VALUE , if the continuation whitespace
ends.
|
SKIPPING_TRAILER_VALUE_WHITESPACE | final public static int SKIPPING_TRAILER_VALUE_WHITESPACE(Code) | |
Description:
Ignoring the continuation whitespace in a multiline trailer.
Next state:
-
SKIPPING_TRAILER_VALUE_WHITESPACE , if SP or HT is
encountered.
-
LOOKING_FOR_TRAILER_VALUE , if the continuation whitespace
ends.
|
SKIPPING_WHITESPACE_AFTER_HEADER_NAME | final public static int SKIPPING_WHITESPACE_AFTER_HEADER_NAME(Code) | |
Description:
Ignoring whitespace before the header value.
Next state:
-
SKIPPING_WHITESPACE_AFTER_HEADER_NAME , if there's more
whitespace.
-
LOOKING_FOR_HEADER_VALUE , if non-whitespace is
encountered.
-
LOOKING_FOR_HEADER_VALUE_OR_NEXT_HEADER , if CR is
encountered.
|
SKIPPING_WHITESPACE_AFTER_TRAILER_NAME | final public static int SKIPPING_WHITESPACE_AFTER_TRAILER_NAME(Code) | |
Description:
Ignoring whitespace before the trailer value.
Next state:
-
SKIPPING_WHITESPACE_AFTER_TRAILER_NAME , if there's more
whitespace.
-
LOOKING_FOR_TRAILER_VALUE , if non-whitespace is
encountered.
-
LOOKING_FOR_TRAILER_VALUE_OR_NEXT_TRAILER , if CR is
encountered.
|
c | protected Context c(Code) | | The basic container for all aspects of the parser state.
|
m_errorHandler | protected HTTPErrorHandler m_errorHandler(Code) | | The handler that will be notified whenever any kind of problem is
encountered.
|
m_handler | protected HTTPHandler m_handler(Code) | | The handler that will be notified whenever some piece of information
about the message is found.
|
HTTPParserImpl | public HTTPParserImpl(HTTPHandler handler, HTTPErrorHandler errorHandler)(Code) | | Create a new instance of the parser. You should create a parser instance
per thread of execution, since the parser is single-threaded and it
saves state between invocations of
HTTPParserImpl.parse(ByteBuffer) .
Parameters: handler - the HTTPHandler where we should direct parsingevents as they occur. Should not be null. Parameters: errorHandler - the HTTPErrorHandler where we should directparsing problems as they occur. Should not be null. |
checkHeaderNameValidity | protected void checkHeaderNameValidity() throws HTTPException(Code) | | Verify if the character being added to this name is valid.
throws: HTTPException - if the character being added to this name isinvalid. |
checkHeaderValueValidity | protected void checkHeaderValueValidity() throws HTTPException(Code) | | Verify if the character being added to this value is valid.
throws: HTTPException - if the character being added to this value isinvalid. |
checkStartLineFirstFieldValidity | protected void checkStartLineFirstFieldValidity() throws HTTPException(Code) | | Verify if the character being added to this field is valid.
throws: HTTPException - if the character being added to this field isinvalid. |
checkStartLineSecondFieldValidity | protected void checkStartLineSecondFieldValidity() throws HTTPException(Code) | | Verify if the character being added to this field is valid.
throws: HTTPException - if the character being added to this field isinvalid. |
checkStartLineThirdFieldValidity | protected void checkStartLineThirdFieldValidity() throws HTTPException(Code) | | Verify if the character being added to this field is valid.
throws: HTTPException - if the character being added to this field isinvalid. |
doParse | protected void doParse() throws HTTPException(Code) | | This is a nearly clean finite state machine. We take a few shortcuts
to handle things like CRLF. Also, we sometimes "fall through" to the
next state immediately rather than back up a character and run the
machine again.
To undestand the internals of this machine and the choices made, you'll
likely want to refer to the HTTP spec on a routine basis. Also, make
sure to understand the possible states and read their descriptions.
throws: HTTPException - |
doParsingLoop | protected void doParsingLoop() throws HTTPException(Code) | | Run the state machine.
throws: HTTPException - if an exception occurs in the state machine. |
doPostParsingCleanup | protected void doPostParsingCleanup()(Code) | | Clean up after the state machine and make sure the basic
c context is ready for another
HTTPParserImpl.parse(ByteBuffer) invocation.
|
doPreParsingSetup | protected void doPreParsingSetup(ByteBuffer source, int limit) throws HTTPException(Code) | | Prepare for running the state machine and initialize the basic
c context .
Parameters: source - the source for the HTTP message. Parameters: limit - up to where to read from the source. throws: HTTPException - if the source is too large. |
findSizeOfNormalBody | protected void findSizeOfNormalBody() throws HTTPException(Code) | | Handle transition from
LOOKING_FOR_NORMAL_BODY to
LOOKING_FOR_NORMAL_BODY_UP_TO_SIZE or
DONE .
|
foundHeaderName | protected void foundHeaderName()(Code) | | Handle transition from
LOOKING_FOR_HEADER_NAME to
SKIPPING_WHITESPACE_AFTER_HEADER_NAME .
|
foundHeaderValue | protected void foundHeaderValue()(Code) | | Handle transition from
LOOKING_FOR_HEADER_VALUE and
closely related states to
LOOKING_FOR_HEADER_NAME or
a
LOOKING_FOR_BODY body state .
|
foundNormalBody | protected void foundNormalBody()(Code) | | Handle transition from
LOOKING_FOR_NORMAL_BODY_UP_TO_SIZE to
DONE .
|
foundStartLineFirstField | protected void foundStartLineFirstField()(Code) | | Handle transition from
LOOKING_FOR_FIELD1 to
LOOKING_FOR_FIELD2 .
|
foundStartLineSecondField | protected void foundStartLineSecondField()(Code) | | Handle transition from
LOOKING_FOR_FIELD2 to
LOOKING_FOR_FIELD3 .
|
foundStartLineThirdField | protected void foundStartLineThirdField()(Code) | | Handle transition from
LOOKING_FOR_FIELD3 to
LOOKING_FOR_NEW_HEADER .
|
foundTrailerValue | protected void foundTrailerValue()(Code) | | |
getContext | protected Context getContext()(Code) | | Get the basic container for all aspects of the parser state.
the basic container for all aspects of the parser state. |
gotoBodyState | protected void gotoBodyState()(Code) | | Interact with the
m_handler handler to determine what body type
to expect and handle the state transition associated with that body
type. Used for transitioning into the body state.
|
lookForHeaderValue | protected void lookForHeaderValue()(Code) | | Handle transition from
SKIPPING_HEADER_VALUE_WHITESPACE to
LOOKING_FOR_HEADER_VALUE .
|
parse | public void parse(ByteBuffer source) throws HTTPException(Code) | | Parse a piece of an HTTP message. Equivalent to calling
parse( source, source.limit() );
Parameters: source - the buffer to read from. Note that you shouldnever modify this buffer after passing it to the parser! throws: HTTPException - See Also: HTTPParser#parse(ByteBuffer). |
parse | public void parse(ByteBuffer source, int limit) throws HTTPException(Code) | | Parse a piece of an HTTP message. The buffer will be read
from its current position up to its limit. On return, the
buffers position will be at its end.
Parameters: source - the buffer to read from. Note that you shouldnever modify this buffer after passing it to the parser! Parameters: limit - the number of bytes to read from the source throws: HTTPException - See Also: HTTPParser#parse(ByteBuffer,int). |
reset | public void reset()(Code) | | Re-initialize the parser, throwing away all current parser state.
See Also: HTTPParser#reset(). |
setContext | protected void setContext(Context context)(Code) | | Set the basic container for all aspects of the parser state. Should
not be null.
Parameters: context - the basic container for all aspects of the parser state. |
setErrorHandler | public void setErrorHandler(HTTPErrorHandler errorHandler)(Code) | | Set the
HTTPErrorHandler where we should direct
parsing problems as they occur. Should not be null.
Parameters: errorHandler - the HTTPErrorHandler where we should directparsing problems as they occur. |
setHandler | public void setHandler(HTTPHandler handler)(Code) | | Set the
HTTPHandler where we should direct parsing
events as they occur. Should not be null.
Parameters: handler - the HTTPHandler where we should direct parsingevents as they occur. |
|
|