Top Description Inners Fields Constructors Methods
org.eclipse.jetty.http

public Class HttpParser

extends Object
Class Inheritance
Imports
java.nio.ByteBuffer, java.nio.charset.StandardCharsets, java.util.ArrayList, .EnumSet, .LinkedHashMap, .List, .Locale, .Map, org.eclipse.jetty.http.HttpTokens.EndOfContent, org.eclipse.jetty.util.BufferUtil, .HostPort, .Index, .NanoTime, .StringUtil, .Utf8StringBuilder, org.slf4j.Logger, .LoggerFactory

A Parser for 1.0 and 1.1 as defined by RFC7230

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 HttpHandler instance the parser is constructed with. If the passed handler is a RequestHandler then server side parsing is performed and if it is a ResponseHandler, then client side parsing is done.

The contract of the 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 RequestHandler#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
RFC 7230

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public static enum
public static interface
private static class
public static interface
public static interface
public static enum

Field Summary

Modifier and TypeField and Description
private static final EnumSet<HttpParser.State>
private static final EnumSet<HttpParser.State>
private static final EnumSet<HttpParser.State>
private long
private int
private int
private final HttpCompliance
private ByteBuffer
private long
private long
private boolean
private HttpTokens.EndOfContent
private volatile boolean
private HttpField
private final HttpParser.FieldCache
private volatile HttpParser.FieldState
private final HttpParser.HttpHandler
private boolean
private boolean
private HttpHeader
private int
private boolean
private String
private boolean
private int
private final int
private HttpMethod
private String
private String
private final HttpParser.RequestHandler
private final HttpParser.ResponseHandler
private int
private volatile HttpParser.State
private final StringBuilder
private final Utf8StringBuilder
private String
private HttpVersion
public static final Index<HttpField>
CACHE

Cache of common HttpFields including:

  • Common static combinations such as:
    • Connection: close
    • Accept-Encoding: gzip
    • Content-Length: 0
private final boolean
private static final int
private static final int
private static final int
private static final int
public static final int
private static final int
public static final Logger
private static final int
private static final Index.Mutable<HttpField>

Constructor Summary

AccessConstructor and Description
public
public
public
HttpParser(HttpParser.RequestHandler handler, int maxHeaderBytes)

public
HttpParser(HttpParser.ResponseHandler handler, int maxHeaderBytes)

public
public
HttpParser(HttpParser.RequestHandler handler, int maxHeaderBytes, HttpCompliance compliance)

public
HttpParser(HttpParser.ResponseHandler handler, int maxHeaderBytes, HttpCompliance compliance)

private
HttpParser(HttpParser.RequestHandler requestHandler, HttpParser.ResponseHandler responseHandler, int maxHeaderBytes, HttpCompliance compliance)

Method Summary

Modifier and TypeMethod and Description
public void
atEOF()

Signal that the associated data source is at EOF

protected void
protected String
private void
protected void
public void
close()

Request that the associated data source be closed

private static HttpCompliance
private long
public long
public long
public long
public Index<HttpField>
public HttpParser.HttpHandler
public int
public int
public HttpParser.State
private boolean
private boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
private HttpTokens.Token
next(ByteBuffer buffer)

protected boolean
private void
private void
protected boolean
private boolean
public boolean

Returns:

True if an RequestHandler method was called and it returned true;
parseNext
(ByteBuffer
the buffer to parse
buffer
)

Parse until next Event.

private void
protected void
protected void
public void
public void
public void
setHeaderCacheCaseSensitive(boolean headerCacheCaseSensitive)

public void
setHeaderCacheSize(int headerCacheSize)

public void
setHeadResponse(boolean
true if head response is expected
head
)

Set if a HEAD response is expected

protected void
setResponseStatus(int status)

protected void
protected void
private void
private String
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait