Package io.netty.handler.codec.http2
Class Http2CodecUtil
java.lang.Object
io.netty.handler.codec.http2.Http2CodecUtil
Constants and utility method used for encoding/decoding HTTP2 frames.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
Provides the ability to associate the outcome of multipleChannelPromise
objects into a singleChannelPromise
object. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ByteBuf
static final int
static final int
static final int
static final long
static final long
static final int
static final int
static final int
(package private) static final int
(package private) static final int
static final short
static final int
static final int
static final int
static final int
static final CharSequence
static final CharSequence
static final int
static final int
static final long
static final int
static final int
static final long
static final long
static final int
static final int
The maximum number of padding bytes.private static final int
static final short
static final long
static final short
static final long
static final long
static final long
static final int
static final short
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final char
static final char
static final char
static final char
static final char
static final char
static final char
static final int
The assumed minimum value forSETTINGS_MAX_CONCURRENT_STREAMS
as recommended by the HTTP/2 spec.static final CharSequence
static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic long
calculateMaxHeaderListSizeGoAway
(long maxHeaderListSize) Calculate the threshold in bytes which should trigger aGO_AWAY
if a set of headers exceeds this amount.static ByteBuf
Returns a buffer containing theCONNECTION_PREFACE
.static Http2Exception
Iteratively looks through the causality chain for the given exception and returns the firstHttp2Exception
ornull
if none.static void
headerListSizeExceeded
(int streamId, long maxHeaderListSize, boolean onDecode) Results in a RST_STREAM being sent forstreamId
due to violating SETTINGS_MAX_HEADER_LIST_SIZE.static void
headerListSizeExceeded
(long maxHeaderListSize) Results in a GO_AWAY being sent due to violating SETTINGS_MAX_HEADER_LIST_SIZE in an unrecoverable manner.static boolean
isMaxFrameSizeValid
(int maxFrameSize) Indicates whether or not the given value for max frame size falls within the valid range.static boolean
isOutboundStream
(boolean server, int streamId) Returnstrue
if the stream is an outbound stream.static boolean
isStreamIdValid
(int streamId) Returns true if thestreamId
is a valid HTTP/2 stream identifier.(package private) static boolean
isStreamIdValid
(int streamId, boolean server) static int
readUnsignedInt
(ByteBuf buf) Reads a big-endian (31-bit) integer from the buffer.static int
Calculate the amount of bytes that can be sent bystate
.static ByteBuf
toByteBuf
(ChannelHandlerContext ctx, Throwable cause) Creates a buffer containing the error message from the given exception.static void
verifyPadding
(int padding) static void
writeFrameHeader
(ByteBuf out, int payloadLength, byte type, Http2Flags flags, int streamId) Writes an HTTP/2 frame header to the output buffer.(package private) static void
writeFrameHeaderInternal
(ByteBuf out, int payloadLength, byte type, Http2Flags flags, int streamId)
-
Field Details
-
CONNECTION_STREAM_ID
public static final int CONNECTION_STREAM_ID- See Also:
-
HTTP_UPGRADE_STREAM_ID
public static final int HTTP_UPGRADE_STREAM_ID- See Also:
-
HTTP_UPGRADE_SETTINGS_HEADER
-
HTTP_UPGRADE_PROTOCOL_NAME
-
TLS_UPGRADE_PROTOCOL_NAME
-
PING_FRAME_PAYLOAD_LENGTH
public static final int PING_FRAME_PAYLOAD_LENGTH- See Also:
-
MAX_UNSIGNED_BYTE
public static final short MAX_UNSIGNED_BYTE- See Also:
-
MAX_PADDING
public static final int MAX_PADDINGThe maximum number of padding bytes. That is the 255 padding bytes appended to the end of a frame and the 1 byte pad length field.- See Also:
-
MAX_UNSIGNED_INT
public static final long MAX_UNSIGNED_INT- See Also:
-
FRAME_HEADER_LENGTH
public static final int FRAME_HEADER_LENGTH- See Also:
-
SETTING_ENTRY_LENGTH
public static final int SETTING_ENTRY_LENGTH- See Also:
-
PRIORITY_ENTRY_LENGTH
public static final int PRIORITY_ENTRY_LENGTH- See Also:
-
INT_FIELD_LENGTH
public static final int INT_FIELD_LENGTH- See Also:
-
MAX_WEIGHT
public static final short MAX_WEIGHT- See Also:
-
MIN_WEIGHT
public static final short MIN_WEIGHT- See Also:
-
CONNECTION_PREFACE
-
MAX_PADDING_LENGTH_LENGTH
private static final int MAX_PADDING_LENGTH_LENGTH- See Also:
-
DATA_FRAME_HEADER_LENGTH
public static final int DATA_FRAME_HEADER_LENGTH- See Also:
-
HEADERS_FRAME_HEADER_LENGTH
public static final int HEADERS_FRAME_HEADER_LENGTH- See Also:
-
PRIORITY_FRAME_LENGTH
public static final int PRIORITY_FRAME_LENGTH- See Also:
-
RST_STREAM_FRAME_LENGTH
public static final int RST_STREAM_FRAME_LENGTH- See Also:
-
PUSH_PROMISE_FRAME_HEADER_LENGTH
public static final int PUSH_PROMISE_FRAME_HEADER_LENGTH- See Also:
-
GO_AWAY_FRAME_HEADER_LENGTH
public static final int GO_AWAY_FRAME_HEADER_LENGTH- See Also:
-
WINDOW_UPDATE_FRAME_LENGTH
public static final int WINDOW_UPDATE_FRAME_LENGTH- See Also:
-
CONTINUATION_FRAME_HEADER_LENGTH
public static final int CONTINUATION_FRAME_HEADER_LENGTH- See Also:
-
SETTINGS_HEADER_TABLE_SIZE
public static final char SETTINGS_HEADER_TABLE_SIZE- See Also:
-
SETTINGS_ENABLE_PUSH
public static final char SETTINGS_ENABLE_PUSH- See Also:
-
SETTINGS_MAX_CONCURRENT_STREAMS
public static final char SETTINGS_MAX_CONCURRENT_STREAMS- See Also:
-
SETTINGS_INITIAL_WINDOW_SIZE
public static final char SETTINGS_INITIAL_WINDOW_SIZE- See Also:
-
SETTINGS_MAX_FRAME_SIZE
public static final char SETTINGS_MAX_FRAME_SIZE- See Also:
-
SETTINGS_MAX_HEADER_LIST_SIZE
public static final char SETTINGS_MAX_HEADER_LIST_SIZE- See Also:
-
SETTINGS_ENABLE_CONNECT_PROTOCOL
public static final char SETTINGS_ENABLE_CONNECT_PROTOCOL- See Also:
-
NUM_STANDARD_SETTINGS
public static final int NUM_STANDARD_SETTINGS- See Also:
-
MAX_HEADER_TABLE_SIZE
public static final long MAX_HEADER_TABLE_SIZE- See Also:
-
MAX_CONCURRENT_STREAMS
public static final long MAX_CONCURRENT_STREAMS- See Also:
-
MAX_INITIAL_WINDOW_SIZE
public static final int MAX_INITIAL_WINDOW_SIZE- See Also:
-
MAX_FRAME_SIZE_LOWER_BOUND
public static final int MAX_FRAME_SIZE_LOWER_BOUND- See Also:
-
MAX_FRAME_SIZE_UPPER_BOUND
public static final int MAX_FRAME_SIZE_UPPER_BOUND- See Also:
-
MAX_HEADER_LIST_SIZE
public static final long MAX_HEADER_LIST_SIZE- See Also:
-
MIN_HEADER_TABLE_SIZE
public static final long MIN_HEADER_TABLE_SIZE- See Also:
-
MIN_CONCURRENT_STREAMS
public static final long MIN_CONCURRENT_STREAMS- See Also:
-
MIN_INITIAL_WINDOW_SIZE
public static final int MIN_INITIAL_WINDOW_SIZE- See Also:
-
MIN_HEADER_LIST_SIZE
public static final long MIN_HEADER_LIST_SIZE- See Also:
-
DEFAULT_WINDOW_SIZE
public static final int DEFAULT_WINDOW_SIZE- See Also:
-
DEFAULT_PRIORITY_WEIGHT
public static final short DEFAULT_PRIORITY_WEIGHT- See Also:
-
DEFAULT_HEADER_TABLE_SIZE
public static final int DEFAULT_HEADER_TABLE_SIZE- See Also:
-
DEFAULT_HEADER_LIST_SIZE
public static final long DEFAULT_HEADER_LIST_SIZEThe initial value of this setting is unlimited. However in practice we don't want to allow our peers to use unlimited memory by default. So we take advantage of theFor any given request, a lower limit than what is advertised MAY be enforced.
loophole.- See Also:
-
DEFAULT_MAX_FRAME_SIZE
public static final int DEFAULT_MAX_FRAME_SIZE- See Also:
-
SMALLEST_MAX_CONCURRENT_STREAMS
public static final int SMALLEST_MAX_CONCURRENT_STREAMSThe assumed minimum value forSETTINGS_MAX_CONCURRENT_STREAMS
as recommended by the HTTP/2 spec.- See Also:
-
DEFAULT_MAX_RESERVED_STREAMS
static final int DEFAULT_MAX_RESERVED_STREAMS- See Also:
-
DEFAULT_MIN_ALLOCATION_CHUNK
static final int DEFAULT_MIN_ALLOCATION_CHUNK- See Also:
-
DEFAULT_GRACEFUL_SHUTDOWN_TIMEOUT_MILLIS
public static final long DEFAULT_GRACEFUL_SHUTDOWN_TIMEOUT_MILLIS -
DEFAULT_MAX_QUEUED_CONTROL_FRAMES
public static final int DEFAULT_MAX_QUEUED_CONTROL_FRAMES- See Also:
-
-
Constructor Details
-
Http2CodecUtil
private Http2CodecUtil()
-
-
Method Details
-
calculateMaxHeaderListSizeGoAway
public static long calculateMaxHeaderListSizeGoAway(long maxHeaderListSize) Calculate the threshold in bytes which should trigger aGO_AWAY
if a set of headers exceeds this amount.- Parameters:
maxHeaderListSize
- SETTINGS_MAX_HEADER_LIST_SIZE for the local endpoint.- Returns:
- the threshold in bytes which should trigger a
GO_AWAY
if a set of headers exceeds this amount.
-
isOutboundStream
public static boolean isOutboundStream(boolean server, int streamId) Returnstrue
if the stream is an outbound stream.- Parameters:
server
-true
if the endpoint is a server,false
otherwise.streamId
- the stream identifier
-
isStreamIdValid
public static boolean isStreamIdValid(int streamId) Returns true if thestreamId
is a valid HTTP/2 stream identifier. -
isStreamIdValid
static boolean isStreamIdValid(int streamId, boolean server) -
isMaxFrameSizeValid
public static boolean isMaxFrameSizeValid(int maxFrameSize) Indicates whether or not the given value for max frame size falls within the valid range. -
connectionPrefaceBuf
Returns a buffer containing theCONNECTION_PREFACE
. -
getEmbeddedHttp2Exception
Iteratively looks through the causality chain for the given exception and returns the firstHttp2Exception
ornull
if none. -
toByteBuf
Creates a buffer containing the error message from the given exception. If the cause isnull
returns an empty buffer. -
readUnsignedInt
Reads a big-endian (31-bit) integer from the buffer. -
writeFrameHeader
public static void writeFrameHeader(ByteBuf out, int payloadLength, byte type, Http2Flags flags, int streamId) Writes an HTTP/2 frame header to the output buffer. -
streamableBytes
Calculate the amount of bytes that can be sent bystate
. The lower bound is0
. -
headerListSizeExceeded
public static void headerListSizeExceeded(int streamId, long maxHeaderListSize, boolean onDecode) throws Http2Exception Results in a RST_STREAM being sent forstreamId
due to violating SETTINGS_MAX_HEADER_LIST_SIZE.- Parameters:
streamId
- The stream ID that was being processed when the exceptional condition occurred.maxHeaderListSize
- The max allowed size for a list of headers in bytes which was exceeded.onDecode
-true
if the exception was encountered during decoder.false
for encode.- Throws:
Http2Exception
- a stream error.
-
headerListSizeExceeded
Results in a GO_AWAY being sent due to violating SETTINGS_MAX_HEADER_LIST_SIZE in an unrecoverable manner.- Parameters:
maxHeaderListSize
- The max allowed size for a list of headers in bytes which was exceeded.- Throws:
Http2Exception
- a connection error.
-
writeFrameHeaderInternal
static void writeFrameHeaderInternal(ByteBuf out, int payloadLength, byte type, Http2Flags flags, int streamId) -
verifyPadding
public static void verifyPadding(int padding)
-