- java.lang.Object
-
- io.netty5.handler.codec.http2.Http2CodecUtil
-
@UnstableApi public final class Http2CodecUtil extends Object
Constants and utility method used for encoding/decoding HTTP2 frames.
-
-
Field Summary
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long
calculateMaxHeaderListSizeGoAway(long maxHeaderListSize)
Calculate the threshold in bytes which should trigger aGO_AWAY
if a set of headers exceeds this amount.static Buffer
connectionPrefaceBuffer()
Returns a buffer containing theCONNECTION_PREFACE_BUFFER
.static Http2Exception
getEmbeddedHttp2Exception(Throwable cause)
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.static int
readUnsignedInt(Buffer buf)
Reads a big-endian (31-bit) integer from the buffer.static int
streamableBytes(StreamByteDistributor.StreamState state)
Calculate the amount of bytes that can be sent bystate
.static Buffer
toBuffer(ChannelHandlerContext ctx, Throwable cause)
Creates a buffer containing the error message from the given exception.static void
verifyPadding(int padding)
static void
writeFrameHeader(Buffer out, int payloadLength, byte type, Http2Flags flags, int streamId)
Writes an HTTP/2 frame header to the output buffer.
-
-
-
Field Detail
-
CONNECTION_STREAM_ID
public static final int CONNECTION_STREAM_ID
- See Also:
- Constant Field Values
-
HTTP_UPGRADE_STREAM_ID
public static final int HTTP_UPGRADE_STREAM_ID
- See Also:
- Constant Field Values
-
HTTP_UPGRADE_SETTINGS_HEADER
public static final CharSequence HTTP_UPGRADE_SETTINGS_HEADER
-
HTTP_UPGRADE_PROTOCOL_NAME
public static final CharSequence HTTP_UPGRADE_PROTOCOL_NAME
-
TLS_UPGRADE_PROTOCOL_NAME
public static final CharSequence TLS_UPGRADE_PROTOCOL_NAME
-
PING_FRAME_PAYLOAD_LENGTH
public static final int PING_FRAME_PAYLOAD_LENGTH
- See Also:
- Constant Field Values
-
MAX_UNSIGNED_BYTE
public static final short MAX_UNSIGNED_BYTE
- See Also:
- Constant Field Values
-
MAX_PADDING
public static final int MAX_PADDING
The 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:
- Constant Field Values
-
MAX_UNSIGNED_INT
public static final long MAX_UNSIGNED_INT
- See Also:
- Constant Field Values
-
FRAME_HEADER_LENGTH
public static final int FRAME_HEADER_LENGTH
- See Also:
- Constant Field Values
-
SETTING_ENTRY_LENGTH
public static final int SETTING_ENTRY_LENGTH
- See Also:
- Constant Field Values
-
PRIORITY_ENTRY_LENGTH
public static final int PRIORITY_ENTRY_LENGTH
- See Also:
- Constant Field Values
-
INT_FIELD_LENGTH
public static final int INT_FIELD_LENGTH
- See Also:
- Constant Field Values
-
MAX_WEIGHT
public static final short MAX_WEIGHT
- See Also:
- Constant Field Values
-
MIN_WEIGHT
public static final short MIN_WEIGHT
- See Also:
- Constant Field Values
-
DATA_FRAME_HEADER_LENGTH
public static final int DATA_FRAME_HEADER_LENGTH
- See Also:
- Constant Field Values
-
HEADERS_FRAME_HEADER_LENGTH
public static final int HEADERS_FRAME_HEADER_LENGTH
- See Also:
- Constant Field Values
-
PRIORITY_FRAME_LENGTH
public static final int PRIORITY_FRAME_LENGTH
- See Also:
- Constant Field Values
-
RST_STREAM_FRAME_LENGTH
public static final int RST_STREAM_FRAME_LENGTH
- See Also:
- Constant Field Values
-
PUSH_PROMISE_FRAME_HEADER_LENGTH
public static final int PUSH_PROMISE_FRAME_HEADER_LENGTH
- See Also:
- Constant Field Values
-
GO_AWAY_FRAME_HEADER_LENGTH
public static final int GO_AWAY_FRAME_HEADER_LENGTH
- See Also:
- Constant Field Values
-
WINDOW_UPDATE_FRAME_LENGTH
public static final int WINDOW_UPDATE_FRAME_LENGTH
- See Also:
- Constant Field Values
-
CONTINUATION_FRAME_HEADER_LENGTH
public static final int CONTINUATION_FRAME_HEADER_LENGTH
- See Also:
- Constant Field Values
-
SETTINGS_HEADER_TABLE_SIZE
public static final char SETTINGS_HEADER_TABLE_SIZE
- See Also:
- Constant Field Values
-
SETTINGS_ENABLE_PUSH
public static final char SETTINGS_ENABLE_PUSH
- See Also:
- Constant Field Values
-
SETTINGS_MAX_CONCURRENT_STREAMS
public static final char SETTINGS_MAX_CONCURRENT_STREAMS
- See Also:
- Constant Field Values
-
SETTINGS_INITIAL_WINDOW_SIZE
public static final char SETTINGS_INITIAL_WINDOW_SIZE
- See Also:
- Constant Field Values
-
SETTINGS_MAX_FRAME_SIZE
public static final char SETTINGS_MAX_FRAME_SIZE
- See Also:
- Constant Field Values
-
SETTINGS_MAX_HEADER_LIST_SIZE
public static final char SETTINGS_MAX_HEADER_LIST_SIZE
- See Also:
- Constant Field Values
-
NUM_STANDARD_SETTINGS
public static final int NUM_STANDARD_SETTINGS
- See Also:
- Constant Field Values
-
MAX_HEADER_TABLE_SIZE
public static final long MAX_HEADER_TABLE_SIZE
- See Also:
- Constant Field Values
-
MAX_CONCURRENT_STREAMS
public static final long MAX_CONCURRENT_STREAMS
- See Also:
- Constant Field Values
-
MAX_INITIAL_WINDOW_SIZE
public static final int MAX_INITIAL_WINDOW_SIZE
- See Also:
- Constant Field Values
-
MAX_FRAME_SIZE_LOWER_BOUND
public static final int MAX_FRAME_SIZE_LOWER_BOUND
- See Also:
- Constant Field Values
-
MAX_FRAME_SIZE_UPPER_BOUND
public static final int MAX_FRAME_SIZE_UPPER_BOUND
- See Also:
- Constant Field Values
-
MAX_HEADER_LIST_SIZE
public static final long MAX_HEADER_LIST_SIZE
- See Also:
- Constant Field Values
-
MIN_HEADER_TABLE_SIZE
public static final long MIN_HEADER_TABLE_SIZE
- See Also:
- Constant Field Values
-
MIN_CONCURRENT_STREAMS
public static final long MIN_CONCURRENT_STREAMS
- See Also:
- Constant Field Values
-
MIN_INITIAL_WINDOW_SIZE
public static final int MIN_INITIAL_WINDOW_SIZE
- See Also:
- Constant Field Values
-
MIN_HEADER_LIST_SIZE
public static final long MIN_HEADER_LIST_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_WINDOW_SIZE
public static final int DEFAULT_WINDOW_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_PRIORITY_WEIGHT
public static final short DEFAULT_PRIORITY_WEIGHT
- See Also:
- Constant Field Values
-
DEFAULT_HEADER_TABLE_SIZE
public static final int DEFAULT_HEADER_TABLE_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_HEADER_LIST_SIZE
public static final long DEFAULT_HEADER_LIST_SIZE
The 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:
- Constant Field Values
-
DEFAULT_MAX_FRAME_SIZE
public static final int DEFAULT_MAX_FRAME_SIZE
- See Also:
- Constant Field Values
-
SMALLEST_MAX_CONCURRENT_STREAMS
public static final int SMALLEST_MAX_CONCURRENT_STREAMS
The assumed minimum value forSETTINGS_MAX_CONCURRENT_STREAMS
as recommended by the HTTP/2 spec.- See Also:
- Constant Field Values
-
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:
- Constant Field Values
-
-
Method Detail
-
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.
-
isMaxFrameSizeValid
public static boolean isMaxFrameSizeValid(int maxFrameSize)
Indicates whether or not the given value for max frame size falls within the valid range.
-
connectionPrefaceBuffer
public static Buffer connectionPrefaceBuffer()
Returns a buffer containing theCONNECTION_PREFACE_BUFFER
.
-
getEmbeddedHttp2Exception
public static Http2Exception getEmbeddedHttp2Exception(Throwable cause)
Iteratively looks through the causality chain for the given exception and returns the firstHttp2Exception
ornull
if none.
-
toBuffer
public static Buffer toBuffer(ChannelHandlerContext ctx, Throwable cause)
Creates a buffer containing the error message from the given exception. If the cause isnull
returns an empty buffer.
-
readUnsignedInt
public static int readUnsignedInt(Buffer buf)
Reads a big-endian (31-bit) integer from the buffer.
-
writeFrameHeader
public static void writeFrameHeader(Buffer out, int payloadLength, byte type, Http2Flags flags, int streamId)
Writes an HTTP/2 frame header to the output buffer.
-
streamableBytes
public static int streamableBytes(StreamByteDistributor.StreamState state)
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
public static void headerListSizeExceeded(long maxHeaderListSize) throws Http2Exception
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.
-
verifyPadding
public static void verifyPadding(int padding)
-
-