HttpParser

A Parser for 1.0 and 1.1 as defined by RFC7230 <p> This parser parses HTTP client and server messages from buffers passed in the {@link #parseNext(ByteBuffer)} method. The parsed elements of the HTTP message are passed as event calls to the {@link HttpHandler} instance the parser is constructed with. If the passed handler is a {@link RequestHandler} then server side parsing is performed and if it is a {@link ResponseHandler}, then client side parsing is done. </p> <p> The contract of the {@link HttpHandler} API is that if a call returns true then the call to {@link #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 {@link #parseNext(ByteBuffer)} rather than from within the scope of a call like {@link RequestHandler#messageComplete()} </p> <p> For performance, the parse is heavily dependent on the {@link 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 {@link 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 {@link HttpFields} from previous parsed messages is used to help the parsing of subsequent messages. </p> <p> The parser can work in varying compliance modes: <dl> <dt>RFC7230</dt><dd>(default) Compliance with RFC7230</dd> <dt>RFC2616</dt><dd>Wrapped headers and HTTP/0.9 supported</dd> <dt>LEGACY</dt><dd>(aka STRICT) Adherence to Servlet Specification requirement for exact case of header names, bypassing the header caches, which are case insensitive, otherwise equivalent to RFC2616</dd> </dl>

@see <a href="http://tools.ietf.org/html/rfc7230">RFC 7230</a>

class HttpParser {}

Constructors

this
this(HttpRequestParsingHandler handler)
Undocumented in source.
this
this(HttpResponseParsingHandler handler)
Undocumented in source.
this
this(HttpRequestParsingHandler handler, int maxHeaderBytes)
Undocumented in source.
this
this(HttpResponseParsingHandler handler, int maxHeaderBytes)
Undocumented in source.
this
this(HttpRequestParsingHandler handler, HttpCompliance compliance)
Undocumented in source.
this
this(HttpRequestParsingHandler handler, int maxHeaderBytes, HttpCompliance compliance)
Undocumented in source.
this
this(HttpResponseParsingHandler handler, int maxHeaderBytes, HttpCompliance compliance)
Undocumented in source.

Members

Aliases

ComplianceHandler
deprecated alias ComplianceHandler = ComplianceParsingHandler
Undocumented in source.
HttpHandler
deprecated alias HttpHandler = HttpParsingHandler
Undocumented in source.
RequestHandler
deprecated alias RequestHandler = HttpRequestParsingHandler
Undocumented in source.
ResponseHandler
deprecated alias ResponseHandler = HttpResponseParsingHandler
Undocumented in source.

Enums

CharState
enum CharState
Undocumented in source.
FieldState
enum FieldState
Undocumented in source.
State
enum State
Undocumented in source.

Functions

atEOF
void atEOF()

Signal that the associated data source is at EOF

badMessage
void badMessage(BadMessageException x)
Undocumented in source. Be warned that the author may not have intended to support it.
caseInsensitiveHeader
string caseInsensitiveHeader(string orig, string normative)
Undocumented in source. Be warned that the author may not have intended to support it.
close
void close()

Request that the associated data source be closed

complianceViolation
bool complianceViolation(HttpComplianceSection violation, string reason)

Check RFC compliance violation

getCachedField
HttpField getCachedField(string name)
Undocumented in source. Be warned that the author may not have intended to support it.
getContentLength
long getContentLength()
Undocumented in source. Be warned that the author may not have intended to support it.
getContentRead
long getContentRead()
Undocumented in source. Be warned that the author may not have intended to support it.
getFieldCache
Trie!HttpField getFieldCache()
Undocumented in source. Be warned that the author may not have intended to support it.
getHandler
HttpParsingHandler getHandler()
Undocumented in source. Be warned that the author may not have intended to support it.
getState
State getState()
Undocumented in source. Be warned that the author may not have intended to support it.
handleViolation
void handleViolation(HttpComplianceSection section, string reason)
Undocumented in source. Be warned that the author may not have intended to support it.
inContentState
bool inContentState()
Undocumented in source. Be warned that the author may not have intended to support it.
inHeaderState
bool inHeaderState()
Undocumented in source. Be warned that the author may not have intended to support it.
isAtEOF
bool isAtEOF()
Undocumented in source. Be warned that the author may not have intended to support it.
isChunking
bool isChunking()
Undocumented in source. Be warned that the author may not have intended to support it.
isClose
bool isClose()
Undocumented in source. Be warned that the author may not have intended to support it.
isClosed
bool isClosed()
Undocumented in source. Be warned that the author may not have intended to support it.
isComplete
bool isComplete()
Undocumented in source. Be warned that the author may not have intended to support it.
isIdle
bool isIdle()
Undocumented in source. Be warned that the author may not have intended to support it.
isStart
bool isStart()
Undocumented in source. Be warned that the author may not have intended to support it.
isState
bool isState(State state)
Undocumented in source. Be warned that the author may not have intended to support it.
parseContent
bool parseContent(ByteBuffer buffer)
Undocumented in source. Be warned that the author may not have intended to support it.
parseFields
bool parseFields(ByteBuffer buffer)
Undocumented in source. Be warned that the author may not have intended to support it.
parseNext
bool parseNext(ByteBuffer buffer)

Parse until next Event.

reset
void reset()
Undocumented in source. Be warned that the author may not have intended to support it.
setHeadResponse
void setHeadResponse(bool head)

Set if a HEAD response is expected

setResponseStatus
void setResponseStatus(int status)
Undocumented in source. Be warned that the author may not have intended to support it.
setState
void setState(State state)
Undocumented in source. Be warned that the author may not have intended to support it.
setState
void setState(FieldState state)
Undocumented in source. Be warned that the author may not have intended to support it.
toString
string toString()
Undocumented in source. Be warned that the author may not have intended to support it.

Manifest constants

INITIAL_URI_LENGTH
enum INITIAL_URI_LENGTH;
Undocumented in source.

Static functions

CACHE
Trie!HttpField CACHE()

Cache of common {@link HttpField}s including: <UL> <LI>Common static combinations such as:<UL> <li>Connection: close <li>Accept-Encoding: gzip <li>Content-Length: 0 </ul> <li>Combinations of Content-Type header for common mime types by common charsets <li>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 </ul>

Meta