public class HttpParser extends Object
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
Trie.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.
If the system property "org.eclipse.jetty.http.HttpParser.STRICT" is set to true, then the parser will strictly pass on the exact strings received for methods and header fields. Otherwise a fast case insensitive string lookup is used that may alter the case of the method and/or headers
Modifier and Type | Class and Description |
---|---|
static interface |
HttpParser.HttpHandler<T> |
static interface |
HttpParser.ProxyHandler |
static interface |
HttpParser.RequestHandler<T> |
static interface |
HttpParser.ResponseHandler<T> |
static class |
HttpParser.State |
Modifier and Type | Field and Description |
---|---|
static boolean |
__STRICT |
static Trie<HttpField> |
CACHE
Cache of common
HttpField s 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
|
static int |
INITIAL_URI_LENGTH |
static Logger |
LOG |
Constructor and Description |
---|
HttpParser(HttpParser.RequestHandler<ByteBuffer> handler) |
HttpParser(HttpParser.RequestHandler<ByteBuffer> handler,
int maxHeaderBytes) |
HttpParser(HttpParser.RequestHandler<ByteBuffer> handler,
int maxHeaderBytes,
boolean strict) |
HttpParser(HttpParser.ResponseHandler<ByteBuffer> handler) |
HttpParser(HttpParser.ResponseHandler<ByteBuffer> handler,
int maxHeaderBytes) |
HttpParser(HttpParser.ResponseHandler<ByteBuffer> handler,
int maxHeaderBytes,
boolean strict) |
Modifier and Type | Method and Description |
---|---|
void |
atEOF() |
void |
close() |
long |
getContentLength() |
long |
getContentRead() |
Trie<HttpField> |
getFieldCache() |
HttpParser.State |
getState() |
boolean |
inContentState() |
boolean |
inHeaderState() |
boolean |
isAtEOF() |
boolean |
isChunking() |
boolean |
isClosed() |
boolean |
isComplete() |
boolean |
isIdle() |
boolean |
isStart() |
boolean |
isState(HttpParser.State state) |
protected boolean |
parseContent(ByteBuffer buffer) |
protected boolean |
parseHeaders(ByteBuffer buffer) |
boolean |
parseNext(ByteBuffer buffer)
Parse until next Event.
|
void |
reset() |
void |
setHeadResponse(boolean head)
Set if a HEAD response is expected
|
protected void |
setResponseStatus(int status) |
protected void |
setState(HttpParser.State state) |
String |
toString() |
public static final Logger LOG
public static final boolean __STRICT
public static final int INITIAL_URI_LENGTH
public static final Trie<HttpField> CACHE
HttpField
s including: public HttpParser(HttpParser.RequestHandler<ByteBuffer> handler)
public HttpParser(HttpParser.ResponseHandler<ByteBuffer> handler)
public HttpParser(HttpParser.RequestHandler<ByteBuffer> handler, int maxHeaderBytes)
public HttpParser(HttpParser.ResponseHandler<ByteBuffer> handler, int maxHeaderBytes)
public HttpParser(HttpParser.RequestHandler<ByteBuffer> handler, int maxHeaderBytes, boolean strict)
public HttpParser(HttpParser.ResponseHandler<ByteBuffer> handler, int maxHeaderBytes, boolean strict)
public long getContentLength()
public long getContentRead()
public void setHeadResponse(boolean head)
head
- protected void setResponseStatus(int status)
public HttpParser.State getState()
public boolean inContentState()
public boolean inHeaderState()
public boolean isChunking()
public boolean isStart()
public boolean isClosed()
public boolean isIdle()
public boolean isComplete()
public boolean isState(HttpParser.State state)
protected boolean parseHeaders(ByteBuffer buffer)
public boolean parseNext(ByteBuffer buffer)
HttpParser.RequestHandler
method was called and it returned true;protected boolean parseContent(ByteBuffer buffer)
public boolean isAtEOF()
public void atEOF()
public void close()
public void reset()
protected void setState(HttpParser.State state)
Copyright © 1995-2015 Webtide. All Rights Reserved.