Top Description Fields Constructors Methods
io.vertx.core.http.impl

public final Class HttpUtils

extends Object
Class Inheritance
Imports
io.netty.buffer.ByteBuf, .Unpooled, io.netty.channel.Channel, io.netty.handler.codec.http.*, io.netty.handler.codec.http2.Http2Settings, io.netty.util.AsciiString, .CharsetUtil, io.vertx.core.AsyncResult, .Future, .Handler, .MultiMap, io.vertx.core.buffer.Buffer, io.vertx.core.file.AsyncFile, .FileSystem, .OpenOptions, io.vertx.core.http.HttpClosedException, .HttpServerRequest, .HttpServerResponse, .StreamPriority, io.vertx.core.impl.VertxInternal, io.vertx.core.net.HostAndPort, io.vertx.core.net.impl.HostAndPortImpl, io.vertx.core.spi.tracing.TagExtractor, java.io.File, .FileNotFoundException, .IOException, .RandomAccessFile, java.net.InetSocketAddress, .SocketAddress, .URI, .URISyntaxException, java.nio.charset.Charset, .StandardCharsets, java.util.Arrays, .Base64, .List, .Map, java.util.function.Consumer

Various http utils.
Author
Norman Maurer

Field Summary

Modifier and TypeField and Description
pack-priv static final TagExtractor<HttpRequestHead>
pack-priv static final TagExtractor<HttpResponseHead>
pack-priv static final HttpClosedException
private static final int
pack-priv static final StreamPriority
pack-priv static final String
private static final Consumer<CharSequence>
private static final int
private static final int
private static final int
pack-priv static final int
pack-priv static final int
pack-priv static final TagExtractor<HttpServerRequest>
pack-priv static final TagExtractor<HttpServerResponse>
private static final String[]
pack-priv static final HttpClosedException
private static final AsciiString
pack-priv static final String
private static final boolean[]

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static String
public static boolean
pack-priv static Http2Settings
decodeSettings(String base64Settings)

private static void
private static void
public static String
public static void
fromVertxInitialSettings(boolean server, Http2Settings vertxSettings, Http2Settings nettySettings)

public static Http2Settings
public static ByteBuf
generateWSCloseFrameByteBuf(short statusCode, String reason)

pack-priv static String
private static int
indexOfSlash(CharSequence str, int start)

pack-priv static boolean
pack-priv static boolean
public static boolean
public static boolean
public static boolean
private static boolean
matches(CharSequence path, int start, String what)

private static boolean
matches(CharSequence path, int start, String what, boolean exact)

public static String

Returns:

normalized path
normalizePath
(String
raw path
pathname
)

Normalizes a path as per rfc3986.

private static String
normalizePathSlow(String pathname, int indexOfFirstPercent)

pack-priv static MultiMap
params(String uri, Charset charset, boolean semicolonIsNormalChar)

public static int
pack-priv static String
parsePath(String uri)

Extract the path out of the uri.

pack-priv static String
parseQuery(String uri)

Extract the query out of a uri or returns the empty string if no query was found.

public static String
positiveLongToString(long value)

This try hard to cache the first 256 positive longs as strings [0, 255] to avoid the cost of creating a new string for each of them.

public static String

Returns:

normalized path
removeDots
(CharSequence
raw path
path
)

Removed dots as per rfc3986.

pack-priv static void
resolveFile(VertxInternal vertx, String filename, long offset, long length, Handler<AsyncResult<AsyncFile>> resultHandler)

public static URI
resolveURIReference(String base, String ref)

Resolve an URI reference as per rfc3986

public static URI
resolveURIReference(URI base, String ref)

Resolve an URI reference as per rfc3986

pack-priv static void
pack-priv static void
public static HostAndPort

Returns:

The converted instance or null if not applicable.
socketAddressToHostAndPort
(SocketAddress
The socket address to convert
socketAddress
)

Convert a SocketAddress to a HostAndPort.

private static CharSequence
public static CharSequence

Returns:

convert the sequence to a lower case instance
toLowerCase
(CharSequence sequence)

This is optimized for Http headers, which are usually in the form: eg Content-Length, content-length

private static CharSequence
toLowerCase(char[] chars, int firstUpperCase, int length)

pack-priv static HttpVersion
pack-priv static HttpMethod
public static Http2Settings
pack-priv static boolean
private static void
private static void
private static void
validateAsciiRangeHeaderValue(AsciiString value, int off, int length, byte[] asciiChars)

This method is the slow-path generic version of validateAsciiHeaderValue(AsciiString) which is optimized for AsciiString instances which are backed by a 0-offset full-blown byte array.

private static int
validateCrLfChar(CharSequence seq, int state, char ch)

public static void
public static void
public static void
public static void
private static void
private static void
private static void
private static void
validateSequenceHeaderValue(CharSequence seq, int index)

This method is taken as we need to validate the header value for the non-printable characters.

private static void
private static void
private static int
validateValueChar(CharSequence seq, int state, char ch)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CLIENT_HTTP_REQUEST_TAG_EXTRACTORback to summary
pack-priv static final TagExtractor<HttpRequestHead> CLIENT_HTTP_REQUEST_TAG_EXTRACTOR
CLIENT_RESPONSE_TAG_EXTRACTORback to summary
pack-priv static final TagExtractor<HttpResponseHead> CLIENT_RESPONSE_TAG_EXTRACTOR
CONNECTION_CLOSED_EXCEPTIONback to summary
pack-priv static final HttpClosedException CONNECTION_CLOSED_EXCEPTION
CR_STATEback to summary
private static final int CR_STATE
DEFAULT_STREAM_PRIORITYback to summary
pack-priv static final StreamPriority DEFAULT_STREAM_PRIORITY
H2_STREAM_BYTE_DISTRIBUTORback to summary
pack-priv static final String H2_STREAM_BYTE_DISTRIBUTOR
HEADER_VALUE_VALIDATORback to summary
private static final Consumer<CharSequence> HEADER_VALUE_VALIDATOR
HIGHEST_INVALID_VALUE_CHAR_MASKback to summary
private static final int HIGHEST_INVALID_VALUE_CHAR_MASK
LF_STATEback to summary
private static final int LF_STATE
NO_CR_LF_STATEback to summary
private static final int NO_CR_LF_STATE
SC_BAD_GATEWAYback to summary
pack-priv static final int SC_BAD_GATEWAY
SC_SWITCHING_PROTOCOLSback to summary
pack-priv static final int SC_SWITCHING_PROTOCOLS
SERVER_REQUEST_TAG_EXTRACTORback to summary
pack-priv static final TagExtractor<HttpServerRequest> SERVER_REQUEST_TAG_EXTRACTOR
SERVER_RESPONSE_TAG_EXTRACTORback to summary
pack-priv static final TagExtractor<HttpServerResponse> SERVER_RESPONSE_TAG_EXTRACTOR
SMALL_POSITIVE_LONGSback to summary
private static final String[] SMALL_POSITIVE_LONGS
STREAM_CLOSED_EXCEPTIONback to summary
pack-priv static final HttpClosedException STREAM_CLOSED_EXCEPTION
TIMEOUT_EQback to summary
private static final AsciiString TIMEOUT_EQ
UNIFORM_DISTRIBUTORback to summary
pack-priv static final String UNIFORM_DISTRIBUTOR
VALID_H_NAME_ASCII_CHARSback to summary
private static final boolean[] VALID_H_NAME_ASCII_CHARS

Constructor Detail

HttpUtilsback to summary
private HttpUtils()

Method Detail

absoluteURIback to summary
pack-priv static String absoluteURI(String serverOrigin, HttpServerRequest req)
canUpgradeToWebSocketback to summary
public static boolean canUpgradeToWebSocket(HttpServerRequest req)
decodeSettingsback to summary
pack-priv static Http2Settings decodeSettings(String base64Settings)
decodeUnreservedback to summary
private static void decodeUnreserved(StringBuilder path, int start)
decodeUnreservedCharsback to summary
private static void decodeUnreservedChars(StringBuilder path, int start)
encodeSettingsback to summary
public static String encodeSettings(Http2Settings settings)
fromVertxInitialSettingsback to summary
public static void fromVertxInitialSettings(boolean server, Http2Settings vertxSettings, Http2Settings nettySettings)
fromVertxSettingsback to summary
public static Http2Settings fromVertxSettings(Http2Settings settings)
generateWSCloseFrameByteBufback to summary
public static ByteBuf generateWSCloseFrameByteBuf(short statusCode, String reason)
getWebSocketLocationback to summary
pack-priv static String getWebSocketLocation(HttpServerRequest req, boolean ssl) throws Exception
indexOfSlashback to summary
private static int indexOfSlash(CharSequence str, int start)
isConnectOrUpgradeback to summary
pack-priv static boolean isConnectOrUpgrade(HttpMethod method, MultiMap headers)
isKeepAliveback to summary
pack-priv static boolean isKeepAlive(HttpRequest request)
isValidHostAuthorityback to summary
public static boolean isValidHostAuthority(String host)
isValidMultipartContentTypeback to summary
public static boolean isValidMultipartContentType(String contentType)
isValidMultipartMethodback to summary
public static boolean isValidMultipartMethod(HttpMethod method)
matchesback to summary
private static boolean matches(CharSequence path, int start, String what)
matchesback to summary
private static boolean matches(CharSequence path, int start, String what, boolean exact)
normalizePathback to summary
public static String normalizePath(String pathname)

Normalizes a path as per rfc3986. There are 2 extra transformations that are not part of the spec but kept for backwards compatibility: double slash // will be converted to single slash and the path will always start with slash. Null paths are not normalized as nothing can be said about them.

Parameters
pathname:String

raw path

Returns:String

normalized path

normalizePathSlowback to summary
private static String normalizePathSlow(String pathname, int indexOfFirstPercent)
paramsback to summary
pack-priv static MultiMap params(String uri, Charset charset, boolean semicolonIsNormalChar)
parseKeepAliveHeaderTimeoutback to summary
public static int parseKeepAliveHeaderTimeout(CharSequence value)
parsePathback to summary
pack-priv static String parsePath(String uri)

Extract the path out of the uri.

parseQueryback to summary
pack-priv static String parseQuery(String uri)

Extract the query out of a uri or returns the empty string if no query was found.

positiveLongToStringback to summary
public static String positiveLongToString(long value)

This try hard to cache the first 256 positive longs as strings [0, 255] to avoid the cost of creating a new string for each of them.
The size/capacity of the cache is subject to change but this method is expected to be used for hot and frequent code paths.

removeDotsback to summary
public static String removeDots(CharSequence path)

Removed dots as per rfc3986. There is 1 extra transformation that are not part of the spec but kept for backwards compatibility: double slash // will be converted to single slash.

Parameters
path:CharSequence

raw path

Returns:String

normalized path

resolveFileback to summary
pack-priv static void resolveFile(VertxInternal vertx, String filename, long offset, long length, Handler<AsyncResult<AsyncFile>> resultHandler)
resolveURIReferenceback to summary
public static URI resolveURIReference(String base, String ref) throws URISyntaxException

Resolve an URI reference as per rfc3986

resolveURIReferenceback to summary
public static URI resolveURIReference(URI base, String ref) throws URISyntaxException

Resolve an URI reference as per rfc3986

sendErrorback to summary
pack-priv static void sendError(Channel ch, HttpResponseStatus status)
sendErrorback to summary
pack-priv static void sendError(Channel ch, HttpResponseStatus status, CharSequence err)
socketAddressToHostAndPortback to summary
public static HostAndPort socketAddressToHostAndPort(SocketAddress socketAddress)

Convert a SocketAddress to a HostAndPort. If the socket address is an InetSocketAddress, the hostString and port are used. Otherwise null is returned.

Parameters
socketAddress:SocketAddress

The socket address to convert

Returns:HostAndPort

The converted instance or null if not applicable.

toCharSequenceLowerCaseback to summary
private static CharSequence toCharSequenceLowerCase(CharSequence sequence)
toLowerCaseback to summary
public static CharSequence toLowerCase(CharSequence sequence)

This is optimized for Http headers, which are usually in the form:
eg Content-Length, content-length

Returns:CharSequence

convert the sequence to a lower case instance

toLowerCaseback to summary
private static CharSequence toLowerCase(char[] chars, int firstUpperCase, int length)
toNettyHttpVersionback to summary
pack-priv static HttpVersion toNettyHttpVersion(HttpVersion version)
toVertxMethodback to summary
pack-priv static HttpMethod toVertxMethod(String method)
toVertxSettingsback to summary
public static Http2Settings toVertxSettings(Http2Settings settings)
useH2UniformStreamByteDistributorback to summary
pack-priv static boolean useH2UniformStreamByteDistributor()
validateAsciiHeaderNameback to summary
private static void validateAsciiHeaderName(AsciiString value)
validateAsciiHeaderValueback to summary
private static void validateAsciiHeaderValue(AsciiString value)
validateAsciiRangeHeaderValueback to summary
private static void validateAsciiRangeHeaderValue(AsciiString value, int off, int length, byte[] asciiChars)

This method is the slow-path generic version of validateAsciiHeaderValue(AsciiString) which is optimized for AsciiString instances which are backed by a 0-offset full-blown byte array.

validateCrLfCharback to summary
private static int validateCrLfChar(CharSequence seq, int state, char ch)
validateHeaderback to summary
public static void validateHeader(CharSequence name, CharSequence value)
validateHeaderback to summary
public static void validateHeader(CharSequence name, Iterable<? extends CharSequence> values)
validateHeaderNameback to summary
public static void validateHeaderName(CharSequence value)
validateHeaderValueback to summary
public static void validateHeaderValue(CharSequence value)
validateNonPrintableCtrlCharback to summary
private static void validateNonPrintableCtrlChar(CharSequence seq, int ch)
validateSequenceHeaderNameback to summary
private static void validateSequenceHeaderName(CharSequence value)
validateSequenceHeaderValueback to summary
private static void validateSequenceHeaderValue(CharSequence value)
validateSequenceHeaderValueback to summary
private static void validateSequenceHeaderValue(CharSequence seq, int index)

This method is taken as we need to validate the header value for the non-printable characters.

validateStringHeaderNameback to summary
private static void validateStringHeaderName(String value)
validateStringHeaderValueback to summary
private static void validateStringHeaderValue(String value)
validateValueCharback to summary
private static int validateValueChar(CharSequence seq, int state, char ch)