Top Description Fields Constructors Methods
io.undertow.server.protocol.http

public abstract Class HttpRequestParser

extends Object
Class Inheritance
Annotations
@HttpParserConfig
methods:OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
protocols:HTTP/0.9, HTTP/1.0, HTTP/1.1, HTTP/2.0
headers:Accept, Accept-Charset, Accept-Encoding, Accept-Language, Accept-Ranges, Authorization, Cache-Control, Cookie, Connection, Content-Length, Content-Type, Expect, From, Host, If-Match, If-Modified-Since, If-None-Match, If-Range, If-Unmodified-Since, Max-Forwards, Origin, Pragma, Proxy-Authorization, Range, Referer, Refresh, Sec-WebSocket-Key, Sec-WebSocket-Version, Server, SSL_CLIENT_CERT, SSL_CIPHER, SSL_SESSION_ID, SSL_CIPHER_USEKEYSIZE, Strict-Transport-Security, Trailer, Transfer-Encoding, Upgrade, User-Agent, Via, Warning
Imports
java.io.UnsupportedEncodingException, java.lang.reflect.Constructor, .Field, java.nio.ByteBuffer, java.nio.charset.StandardCharsets, java.util.HashMap, .Map, io.undertow.UndertowMessages, .UndertowOptions, io.undertow.annotationprocessor.HttpParserConfig, io.undertow.server.HttpServerExchange, io.undertow.util.Headers, .HttpString, .Methods, .Protocols, .URLUtils, .BadRequestException, .Cookies, org.xnio.OptionMap

The basic HTTP parser. The actual parser is a sub class of this class that is generated as part of the build process by the io.undertow.annotationprocessor.AbstractParserGenerator annotation processor.

The actual processor is a state machine, that means that for common header, method, protocol values it will return an interned string, rather than creating a new string for each one.

Author
Stuart Douglas

Field Summary

Modifier and TypeField and Description
private static final boolean[]
private final boolean
private final boolean
private static final int
private static final int
private final String
private final boolean
private static final int
private static final int
private static final int
private static final byte[]
public static final int
private static final String
private static final int
private static final int
private final int
private final int
private final int
private static final int
NORMAL

The parse states for parsing heading values

private static final int
private static final int
private static final int
private static final int
private final boolean
private static final int
START

The parse states for parsing the path.

private static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
beginQueryParameters(ByteBuffer buffer, ParseState state, HttpServerExchange exchange, StringBuilder stringBuilder, int parseState, int canonicalPathStart, boolean urlDecodeRequired)

private String
decode(final String value, boolean urlDecodeRequired, ParseState state, final boolean slashDecodingFlag, final boolean formEncoded)

public void
handle(ByteBuffer buffer, final ParseState currentState, final HttpServerExchange builder)

protected void
protected boolean
private void
handleFullUrl(ParseState state, HttpServerExchange exchange, int canonicalPathStart, boolean urlDecodeRequired, String path, int parseState)

pack-priv abstract void
handleHeader(ByteBuffer buffer, final ParseState currentState, final HttpServerExchange builder)

pack-priv final void

Returns:

The number of bytes remaining
handleHeaderValue
(ByteBuffer
The buffer
buffer
,
ParseState
The current state
state
,
HttpServerExchange
The exchange builder
builder
)

Parses a header value.

private void
handleHeaderValueCacheMiss(ByteBuffer buffer, ParseState state, HttpServerExchange builder, HttpString headerName, CacheMap<HttpString, String> headerValuesCache, StringBuilder stringBuilder)

pack-priv abstract void
handleHttpVerb(ByteBuffer buffer, final ParseState currentState, final HttpServerExchange builder)

pack-priv abstract void
handleHttpVersion(ByteBuffer buffer, final ParseState currentState, final HttpServerExchange builder)

private void
handleParsedParam(String paramName, String parameterValue, HttpServerExchange exchange, boolean urlDecodeRequired, ParseState state)

pack-priv final void

Returns:

The number of bytes remaining
handlePath
(ByteBuffer
The buffer
buffer
,
ParseState
The current state
state
,
HttpServerExchange
The exchange builder
exchange
)

Parses a path value

pack-priv final void
handlePathParameters(ByteBuffer buffer, ParseState state, HttpServerExchange exchange)

This method should only ever be called if the path contains am non-decoded semi colon character ';'

pack-priv final void

Returns:

The number of bytes remaining
handleQueryParameters
(ByteBuffer
The buffer
buffer
,
ParseState
The current state
state
,
HttpServerExchange
The exchange builder
exchange
)

Parses query string parameters

private void
handleStateful(ByteBuffer buffer, ParseState currentState, HttpServerExchange builder)

protected static Map<String, HttpString>
httpStrings()

This is a bit of hack to enable the parser to get access to the HttpString's that are sorted in the static fields of the relevant classes.

public static final HttpRequestParser
instance(final OptionMap options)

public static boolean
private void
parsePathComplete(ParseState state, HttpServerExchange exchange, int canonicalPathStart, int parseState, boolean urlDecodeRequired, String path)

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ALLOWED_TARGET_CHARACTERback to summary
private static final boolean[] ALLOWED_TARGET_CHARACTER
allowIDLessMatrixParamsback to summary
private final boolean allowIDLessMatrixParams
allowUnescapedCharactersInUrlback to summary
private final boolean allowUnescapedCharactersInUrl
AWAIT_DATA_ENDback to summary
private static final int AWAIT_DATA_END
BEGIN_LINE_ENDback to summary
private static final int BEGIN_LINE_END
charsetback to summary
private final String charset
decodeback to summary
private final boolean decode
FIRST_COLONback to summary
private static final int FIRST_COLON
FIRST_SLASHback to summary
private static final int FIRST_SLASH
HOST_DONEback to summary
private static final int HOST_DONE
HTTPback to summary
private static final byte[] HTTP
HTTP_LENGTHback to summary
public static final int HTTP_LENGTH
ID_LESS_MATRIX_PARAMS_PROPERTYback to summary
private static final String ID_LESS_MATRIX_PARAMS_PROPERTY
IN_PATHback to summary
private static final int IN_PATH
LINE_ENDback to summary
private static final int LINE_END
maxCachedHeaderSizeback to summary
private final int maxCachedHeaderSize
maxHeadersback to summary
private final int maxHeaders
maxParametersback to summary
private final int maxParameters
NORMALback to summary
private static final int NORMAL

The parse states for parsing heading values

PATH_DOT_SEGMENTback to summary
private static final int PATH_DOT_SEGMENT
PATH_NON_DOT_SEGMENTback to summary
private static final int PATH_NON_DOT_SEGMENT
PATH_SEGMENT_STARTback to summary
private static final int PATH_SEGMENT_START
SECOND_SLASHback to summary
private static final int SECOND_SLASH
slashDecodingFlagback to summary
private final boolean slashDecodingFlag
STARTback to summary
private static final int START

The parse states for parsing the path.

WHITESPACEback to summary
private static final int WHITESPACE

Constructor Detail

HttpRequestParserback to summary
public HttpRequestParser(OptionMap options)

Method Detail

beginQueryParametersback to summary
private void beginQueryParameters(ByteBuffer buffer, ParseState state, HttpServerExchange exchange, StringBuilder stringBuilder, int parseState, int canonicalPathStart, boolean urlDecodeRequired) throws BadRequestException
decodeback to summary
private String decode(final String value, boolean urlDecodeRequired, ParseState state, final boolean slashDecodingFlag, final boolean formEncoded)
handleback to summary
public void handle(ByteBuffer buffer, final ParseState currentState, final HttpServerExchange builder) throws BadRequestException
handleAfterVersionback to summary
protected void handleAfterVersion(ByteBuffer buffer, ParseState state) throws BadRequestException
handleCachedHeaderback to summary
protected boolean handleCachedHeader(String existing, ByteBuffer buffer, ParseState state, HttpServerExchange builder) throws BadRequestException
handleFullUrlback to summary
private void handleFullUrl(ParseState state, HttpServerExchange exchange, int canonicalPathStart, boolean urlDecodeRequired, String path, int parseState)
handleHeaderback to summary
pack-priv abstract void handleHeader(ByteBuffer buffer, final ParseState currentState, final HttpServerExchange builder) throws BadRequestException
handleHeaderValueback to summary
pack-priv final void handleHeaderValue(ByteBuffer buffer, ParseState state, HttpServerExchange builder) throws BadRequestException

Parses a header value. This is called from the generated bytecode.

Parameters
buffer:ByteBuffer

The buffer

state:ParseState

The current state

builder:HttpServerExchange

The exchange builder

Returns:void

The number of bytes remaining

Annotations
@SuppressWarnings:unused
handleHeaderValueCacheMissback to summary
private void handleHeaderValueCacheMiss(ByteBuffer buffer, ParseState state, HttpServerExchange builder, HttpString headerName, CacheMap<HttpString, String> headerValuesCache, StringBuilder stringBuilder) throws BadRequestException
handleHttpVerbback to summary
pack-priv abstract void handleHttpVerb(ByteBuffer buffer, final ParseState currentState, final HttpServerExchange builder) throws BadRequestException
handleHttpVersionback to summary
pack-priv abstract void handleHttpVersion(ByteBuffer buffer, final ParseState currentState, final HttpServerExchange builder) throws BadRequestException
handleParsedParamback to summary
private void handleParsedParam(String paramName, String parameterValue, HttpServerExchange exchange, boolean urlDecodeRequired, ParseState state) throws BadRequestException
handlePathback to summary
pack-priv final void handlePath(ByteBuffer buffer, ParseState state, HttpServerExchange exchange) throws BadRequestException

Parses a path value

Parameters
buffer:ByteBuffer

The buffer

state:ParseState

The current state

exchange:HttpServerExchange

The exchange builder

Returns:void

The number of bytes remaining

Annotations
@SuppressWarnings:unused
handlePathParametersback to summary
pack-priv final void handlePathParameters(ByteBuffer buffer, ParseState state, HttpServerExchange exchange) throws BadRequestException

This method should only ever be called if the path contains am non-decoded semi colon character ';'

handleQueryParametersback to summary
pack-priv final void handleQueryParameters(ByteBuffer buffer, ParseState state, HttpServerExchange exchange) throws BadRequestException

Parses query string parameters

Parameters
buffer:ByteBuffer

The buffer

state:ParseState

The current state

exchange:HttpServerExchange

The exchange builder

Returns:void

The number of bytes remaining

Annotations
@SuppressWarnings:unused
handleStatefulback to summary
private void handleStateful(ByteBuffer buffer, ParseState currentState, HttpServerExchange builder) throws BadRequestException
httpStringsback to summary
protected static Map<String, HttpString> httpStrings()

This is a bit of hack to enable the parser to get access to the HttpString's that are sorted in the static fields of the relevant classes. This means that in most cases a HttpString comparison will take the fast path == route, as they will be the same object

Annotations
@SuppressWarnings:unused
instanceback to summary
public static final HttpRequestParser instance(final OptionMap options)
isTargetCharacterAllowedback to summary
public static boolean isTargetCharacterAllowed(char c)
parsePathCompleteback to summary
private void parsePathComplete(ParseState state, HttpServerExchange exchange, int canonicalPathStart, int parseState, boolean urlDecodeRequired, String path)
sanitazeListTypeHeadersback to summary
private void sanitazeListTypeHeaders(final HttpServerExchange builder)