Class HttpParser
This parser parses HTTP client and server messages from buffers
passed in the parseNext(ByteBuffer) method.  The parsed
elements of the HTTP message are passed as event calls to the
HttpParser.HttpHandler instance the parser is constructed with.
If the passed handler is a HttpParser.RequestHandler then server side
parsing is performed and if it is a HttpParser.ResponseHandler, then
client side parsing is done.
The contract of the HttpParser.HttpHandler API is that if a call returns
true then the call to parseNext(ByteBuffer) will return as
soon as possible also with a true response.  Typically this indicates
that the parsing has reached a stage where the caller should process
the events accumulated by the handler.    It is the preferred calling
style that handling such as calling a servlet to process a request,
should be done after a true return from parseNext(ByteBuffer)
rather than from within the scope of a call like
HttpParser.HttpHandler.messageComplete()
For performance, the parse is heavily dependent on the
Index.getBest(ByteBuffer, int, int) method to look ahead in a
single pass for both the structure ( : and CRLF ) and semantic (which
header and value) of a header.  Specifically the static HttpHeader.CACHE
is used to lookup common combinations of headers and values
(eg. "Connection: close"), or just header names (eg. "Connection:" ).
For headers who's value is not known statically (eg. Host, COOKIE) then a
per parser dynamic Trie of HttpFields from previous parsed messages
is used to help the parsing of subsequent messages.
The parser can work in varying compliance modes:
- RFC7230
- (default) Compliance with RFC7230
- RFC2616
- Wrapped headers and HTTP/0.9 supported
- LEGACY
- Adherence to Servlet Specification requirement for exact case of header names, bypassing the header caches, which are case insensitive, otherwise equivalent to RFC2616
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic enumstatic interfacestatic interfacestatic interfacestatic enum
- 
Field SummaryFieldsModifier and TypeFieldDescriptionCache of commonHttpFields including: Common static combinations such as: Connection: close Accept-Encoding: gzip Content-Length: 0 Combinations of Content-Type header for common mime types by common charsets Most common headers with null values so that a lookup will at least determine the header name even if the name:value combination is not cachedstatic final int
- 
Constructor SummaryConstructorsConstructorDescriptionHttpParser(HttpParser.RequestHandler handler) HttpParser(HttpParser.RequestHandler handler, int maxHeaderBytes) HttpParser(HttpParser.RequestHandler handler, int maxHeaderBytes, HttpCompliance compliance) HttpParser(HttpParser.RequestHandler handler, HttpCompliance compliance) HttpParser(HttpParser.ResponseHandler handler) HttpParser(HttpParser.ResponseHandler handler, int maxHeaderBytes) HttpParser(HttpParser.ResponseHandler handler, int maxHeaderBytes, HttpCompliance compliance) 
- 
Method SummaryModifier and TypeMethodDescriptionvoidatEOF()Signal that the associated data source is at EOFprotected voidprotected StringcaseInsensitiveHeader(String orig, String normative) protected voidcheckViolation(HttpCompliance.Violation violation) voidclose()Request that the associated data source be closedlonglonglongintintgetState()booleanbooleanbooleanbooleanisAtEOF()booleanbooleanisClose()booleanisClosed()booleanbooleanbooleanisIdle()booleanisStart()booleanisState(HttpParser.State state) booleanprotected booleanparseContent(ByteBuffer buffer) protected booleanparseFields(ByteBuffer buffer) booleanparseNext(ByteBuffer buffer) Parse until next Event.protected voidprotected voidreportComplianceViolation(HttpCompliance.Violation violation, String reason) voidreset()voidvoidsetHeaderCacheCaseSensitive(boolean headerCacheCaseSensitive) voidsetHeaderCacheSize(int headerCacheSize) voidsetHeadResponse(boolean head) Set if a HEAD response is expectedprotected voidsetResponseStatus(int status) protected voidsetState(HttpParser.FieldState state) protected voidsetState(HttpParser.State state) toString()
- 
Field Details- 
INITIAL_URI_LENGTHpublic static final int INITIAL_URI_LENGTH- See Also:
 
- 
CACHECache of commonHttpFields including:- Common static combinations such as:- Connection: close
- Accept-Encoding: gzip
- Content-Length: 0
 
- Combinations of Content-Type header for common mime types by common charsets
- Most common headers with null values so that a lookup will at least determine the header name even if the name:value combination is not cached
 
- Common static combinations such as:
 
- 
- 
Constructor Details- 
HttpParser
- 
HttpParser
- 
HttpParser
- 
HttpParser
- 
HttpParser
- 
HttpParser
- 
HttpParserpublic HttpParser(HttpParser.ResponseHandler handler, int maxHeaderBytes, HttpCompliance compliance) 
 
- 
- 
Method Details- 
getBeginNanoTimepublic long getBeginNanoTime()
- 
getHandler
- 
getHeaderCacheSizepublic int getHeaderCacheSize()
- 
setHeaderCacheSizepublic void setHeaderCacheSize(int headerCacheSize) 
- 
isHeaderCacheCaseSensitivepublic boolean isHeaderCacheCaseSensitive()
- 
setHeaderCacheCaseSensitivepublic void setHeaderCacheCaseSensitive(boolean headerCacheCaseSensitive) 
- 
checkViolation- Throws:
- BadMessageException
 
- 
reportComplianceViolation
- 
reportComplianceViolation
- 
caseInsensitiveHeader
- 
getContentLengthpublic long getContentLength()
- 
getContentReadpublic long getContentRead()
- 
getHeaderLengthpublic int getHeaderLength()
- 
setHeadResponsepublic void setHeadResponse(boolean head) Set if a HEAD response is expected- Parameters:
- head- true if head response is expected
 
- 
setResponseStatusprotected void setResponseStatus(int status) 
- 
getState
- 
hasContentpublic boolean hasContent()
- 
inContentStatepublic boolean inContentState()
- 
inHeaderStatepublic boolean inHeaderState()
- 
isChunkingpublic boolean isChunking()
- 
isStartpublic boolean isStart()
- 
isClosepublic boolean isClose()
- 
isClosedpublic boolean isClosed()
- 
isIdlepublic boolean isIdle()
- 
isCompletepublic boolean isComplete()
- 
isTerminatedpublic boolean isTerminated()
- 
isState
- 
parseFields
- 
parseNextParse until next Event.- Parameters:
- buffer- the buffer to parse
- Returns:
- True if an HttpParser.RequestHandlermethod was called and it returned true;
 
- 
badMessage
- 
parseContent
- 
isAtEOFpublic boolean isAtEOF()
- 
atEOFpublic void atEOF()Signal that the associated data source is at EOF
- 
closepublic void close()Request that the associated data source be closed
- 
resetpublic void reset()
- 
servletUpgradepublic void servletUpgrade()
- 
setState
- 
setState
- 
getFieldCache
- 
toString
 
-