Top Description Inners Fields Constructors Methods
io.netty5.handler.codec.http2

public final Class Http2CodecUtil

extends Object
Class Inheritance
Annotations
@UnstableApi
Imports
io.netty5.buffer.Buffer, .BufferAllocator, io.netty5.channel.ChannelHandlerContext, io.netty5.handler.ssl.ApplicationProtocolNames, io.netty5.util.AsciiString, io.netty5.util.concurrent.DefaultPromise, .EventExecutor, .Future, .Promise, io.netty5.util.internal.UnstableApi, java.util.function.Supplier

Constants and utility method used for encoding/decoding HTTP2 frames.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
Http2CodecUtil.SimpleChannelPromiseAggregator

Provides the ability to associate the outcome of multiple Promise objects into a single Promise object.

Field Summary

Modifier and TypeField and Description
public static final Supplier<Buffer>
public static final int
public static final int
public static final int
public static final long
public static final long
public static final int
public static final int
public static final int
pack-priv static final int
pack-priv static final int
public static final short
public static final int
public static final int
public static final int
public static final int
public static final CharSequence
public static final CharSequence
public static final int
public static final int
public static final long
public static final int
public static final int
public static final long
public static final long
public static final int
public static final int
MAX_PADDING

The maximum number of padding bytes.

private static final int
public static final short
public static final long
public static final short
public static final long
public static final long
public static final long
public static final int
public static final short
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final char
public static final char
public static final char
public static final char
public static final char
public static final char
public static final int
SMALLEST_MAX_CONCURRENT_STREAMS

The assumed minimum value for SETTINGS_MAX_CONCURRENT_STREAMS as recommended by the HTTP/2 spec.

public static final CharSequence
public static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static long

Returns:

the threshold in bytes which should trigger a GO_AWAY if a set of headers exceeds this amount.
calculateMaxHeaderListSizeGoAway
(long
SETTINGS_MAX_HEADER_LIST_SIZE for the local endpoint.
maxHeaderListSize
)

Calculate the threshold in bytes which should trigger a GO_AWAY if a set of headers exceeds this amount.

public static Buffer
connectionPrefaceBuffer()

Returns a buffer containing the CONNECTION_PREFACE_BUFFER.

public static Http2Exception
getEmbeddedHttp2Exception(Throwable cause)

Iteratively looks through the causality chain for the given exception and returns the first Http2Exception or null if none.

public static void
headerListSizeExceeded(int
The stream ID that was being processed when the exceptional condition occurred.
streamId
,
long
The max allowed size for a list of headers in bytes which was exceeded.
maxHeaderListSize
,
boolean
true if the exception was encountered during decoder. false for encode.
onDecode
)

Results in a RST_STREAM being sent for streamId due to violating SETTINGS_MAX_HEADER_LIST_SIZE.

public static void
headerListSizeExceeded(long
The max allowed size for a list of headers in bytes which was exceeded.
maxHeaderListSize
)

Results in a GO_AWAY being sent due to violating SETTINGS_MAX_HEADER_LIST_SIZE in an unrecoverable manner.

public static boolean
isMaxFrameSizeValid(int maxFrameSize)

Indicates whether or not the given value for max frame size falls within the valid range.

public static boolean
isOutboundStream(boolean
true if the endpoint is a server, false otherwise.
server
,
int
the stream identifier
streamId
)

Returns true if the stream is an outbound stream.

public static boolean
isStreamIdValid(int streamId)

Returns true if the streamId is a valid HTTP/2 stream identifier.

pack-priv static boolean
isStreamIdValid(int streamId, boolean server)

public static int
readUnsignedInt(Buffer buf)

Reads a big-endian (31-bit) integer from the buffer.

public static int
streamableBytes(StreamByteDistributor.StreamState state)

Calculate the amount of bytes that can be sent by state.

public static Buffer
toBuffer(ChannelHandlerContext ctx, Throwable cause)

Creates a buffer containing the error message from the given exception.

public static void
verifyPadding(int padding)

public static void
writeFrameHeader(Buffer out, int payloadLength, byte type, Http2Flags flags, int streamId)

Writes an HTTP/2 frame header to the output buffer.

pack-priv static void
writeFrameHeaderInternal(Buffer out, int payloadLength, byte type, Http2Flags flags, int streamId)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CONNECTION_PREFACE_BUFFERback to summary
public static final Supplier<Buffer> CONNECTION_PREFACE_BUFFER
CONNECTION_STREAM_IDback to summary
public static final int CONNECTION_STREAM_ID
CONTINUATION_FRAME_HEADER_LENGTHback to summary
public static final int CONTINUATION_FRAME_HEADER_LENGTH
DATA_FRAME_HEADER_LENGTHback to summary
public static final int DATA_FRAME_HEADER_LENGTH
DEFAULT_GRACEFUL_SHUTDOWN_TIMEOUT_MILLISback to summary
public static final long DEFAULT_GRACEFUL_SHUTDOWN_TIMEOUT_MILLIS
DEFAULT_HEADER_LIST_SIZEback to summary
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 the For any given request, a lower limit than what is advertised MAY be enforced. loophole.

DEFAULT_HEADER_TABLE_SIZEback to summary
public static final int DEFAULT_HEADER_TABLE_SIZE
DEFAULT_MAX_FRAME_SIZEback to summary
public static final int DEFAULT_MAX_FRAME_SIZE
DEFAULT_MAX_QUEUED_CONTROL_FRAMESback to summary
public static final int DEFAULT_MAX_QUEUED_CONTROL_FRAMES
DEFAULT_MAX_RESERVED_STREAMSback to summary
pack-priv static final int DEFAULT_MAX_RESERVED_STREAMS
DEFAULT_MIN_ALLOCATION_CHUNKback to summary
pack-priv static final int DEFAULT_MIN_ALLOCATION_CHUNK
DEFAULT_PRIORITY_WEIGHTback to summary
public static final short DEFAULT_PRIORITY_WEIGHT
DEFAULT_WINDOW_SIZEback to summary
public static final int DEFAULT_WINDOW_SIZE
FRAME_HEADER_LENGTHback to summary
public static final int FRAME_HEADER_LENGTH
GO_AWAY_FRAME_HEADER_LENGTHback to summary
public static final int GO_AWAY_FRAME_HEADER_LENGTH
HEADERS_FRAME_HEADER_LENGTHback to summary
public static final int HEADERS_FRAME_HEADER_LENGTH
HTTP_UPGRADE_PROTOCOL_NAMEback to summary
public static final CharSequence HTTP_UPGRADE_PROTOCOL_NAME
HTTP_UPGRADE_SETTINGS_HEADERback to summary
public static final CharSequence HTTP_UPGRADE_SETTINGS_HEADER
HTTP_UPGRADE_STREAM_IDback to summary
public static final int HTTP_UPGRADE_STREAM_ID
INT_FIELD_LENGTHback to summary
public static final int INT_FIELD_LENGTH
MAX_CONCURRENT_STREAMSback to summary
public static final long MAX_CONCURRENT_STREAMS
MAX_FRAME_SIZE_LOWER_BOUNDback to summary
public static final int MAX_FRAME_SIZE_LOWER_BOUND
MAX_FRAME_SIZE_UPPER_BOUNDback to summary
public static final int MAX_FRAME_SIZE_UPPER_BOUND
MAX_HEADER_LIST_SIZEback to summary
public static final long MAX_HEADER_LIST_SIZE
MAX_HEADER_TABLE_SIZEback to summary
public static final long MAX_HEADER_TABLE_SIZE
MAX_INITIAL_WINDOW_SIZEback to summary
public static final int MAX_INITIAL_WINDOW_SIZE
MAX_PADDINGback to summary
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.

MAX_PADDING_LENGTH_LENGTHback to summary
private static final int MAX_PADDING_LENGTH_LENGTH
MAX_UNSIGNED_BYTEback to summary
public static final short MAX_UNSIGNED_BYTE
MAX_UNSIGNED_INTback to summary
public static final long MAX_UNSIGNED_INT
MAX_WEIGHTback to summary
public static final short MAX_WEIGHT
MIN_CONCURRENT_STREAMSback to summary
public static final long MIN_CONCURRENT_STREAMS
MIN_HEADER_LIST_SIZEback to summary
public static final long MIN_HEADER_LIST_SIZE
MIN_HEADER_TABLE_SIZEback to summary
public static final long MIN_HEADER_TABLE_SIZE
MIN_INITIAL_WINDOW_SIZEback to summary
public static final int MIN_INITIAL_WINDOW_SIZE
MIN_WEIGHTback to summary
public static final short MIN_WEIGHT
NUM_STANDARD_SETTINGSback to summary
public static final int NUM_STANDARD_SETTINGS
PING_FRAME_PAYLOAD_LENGTHback to summary
public static final int PING_FRAME_PAYLOAD_LENGTH
PRIORITY_ENTRY_LENGTHback to summary
public static final int PRIORITY_ENTRY_LENGTH
PRIORITY_FRAME_LENGTHback to summary
public static final int PRIORITY_FRAME_LENGTH
PUSH_PROMISE_FRAME_HEADER_LENGTHback to summary
public static final int PUSH_PROMISE_FRAME_HEADER_LENGTH
RST_STREAM_FRAME_LENGTHback to summary
public static final int RST_STREAM_FRAME_LENGTH
SETTING_ENTRY_LENGTHback to summary
public static final int SETTING_ENTRY_LENGTH
SETTINGS_ENABLE_PUSHback to summary
public static final char SETTINGS_ENABLE_PUSH
SETTINGS_HEADER_TABLE_SIZEback to summary
public static final char SETTINGS_HEADER_TABLE_SIZE
SETTINGS_INITIAL_WINDOW_SIZEback to summary
public static final char SETTINGS_INITIAL_WINDOW_SIZE
SETTINGS_MAX_CONCURRENT_STREAMSback to summary
public static final char SETTINGS_MAX_CONCURRENT_STREAMS
SETTINGS_MAX_FRAME_SIZEback to summary
public static final char SETTINGS_MAX_FRAME_SIZE
SETTINGS_MAX_HEADER_LIST_SIZEback to summary
public static final char SETTINGS_MAX_HEADER_LIST_SIZE
SMALLEST_MAX_CONCURRENT_STREAMSback to summary
public static final int SMALLEST_MAX_CONCURRENT_STREAMS

The assumed minimum value for SETTINGS_MAX_CONCURRENT_STREAMS as recommended by the HTTP/2 spec.

TLS_UPGRADE_PROTOCOL_NAMEback to summary
public static final CharSequence TLS_UPGRADE_PROTOCOL_NAME
WINDOW_UPDATE_FRAME_LENGTHback to summary
public static final int WINDOW_UPDATE_FRAME_LENGTH

Constructor Detail

Http2CodecUtilback to summary
private Http2CodecUtil()

Method Detail

calculateMaxHeaderListSizeGoAwayback to summary
public static long calculateMaxHeaderListSizeGoAway(long maxHeaderListSize)

Calculate the threshold in bytes which should trigger a GO_AWAY if a set of headers exceeds this amount.

Parameters
maxHeaderListSize:long

SETTINGS_MAX_HEADER_LIST_SIZE for the local endpoint.

Returns:long

the threshold in bytes which should trigger a GO_AWAY if a set of headers exceeds this amount.

connectionPrefaceBufferback to summary
public static Buffer connectionPrefaceBuffer()

Returns a buffer containing the CONNECTION_PREFACE_BUFFER.

getEmbeddedHttp2Exceptionback to summary
public static Http2Exception getEmbeddedHttp2Exception(Throwable cause)

Iteratively looks through the causality chain for the given exception and returns the first Http2Exception or null if none.

headerListSizeExceededback to summary
public static void headerListSizeExceeded(int streamId, long maxHeaderListSize, boolean onDecode) throws Http2Exception

Results in a RST_STREAM being sent for streamId due to violating SETTINGS_MAX_HEADER_LIST_SIZE.

Parameters
streamId:int

The stream ID that was being processed when the exceptional condition occurred.

maxHeaderListSize:long

The max allowed size for a list of headers in bytes which was exceeded.

onDecode:boolean

true if the exception was encountered during decoder. false for encode.

Exceptions
Http2Exception:
a stream error.
headerListSizeExceededback to summary
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:long

The max allowed size for a list of headers in bytes which was exceeded.

Exceptions
Http2Exception:
a connection error.
isMaxFrameSizeValidback to summary
public static boolean isMaxFrameSizeValid(int maxFrameSize)

Indicates whether or not the given value for max frame size falls within the valid range.

isOutboundStreamback to summary
public static boolean isOutboundStream(boolean server, int streamId)

Returns true if the stream is an outbound stream.

Parameters
server:boolean

true if the endpoint is a server, false otherwise.

streamId:int

the stream identifier

isStreamIdValidback to summary
public static boolean isStreamIdValid(int streamId)

Returns true if the streamId is a valid HTTP/2 stream identifier.

isStreamIdValidback to summary
pack-priv static boolean isStreamIdValid(int streamId, boolean server)
readUnsignedIntback to summary
public static int readUnsignedInt(Buffer buf)

Reads a big-endian (31-bit) integer from the buffer.

streamableBytesback to summary
public static int streamableBytes(StreamByteDistributor.StreamState state)

Calculate the amount of bytes that can be sent by state. The lower bound is 0.

toBufferback to summary
public static Buffer toBuffer(ChannelHandlerContext ctx, Throwable cause)

Creates a buffer containing the error message from the given exception. If the cause is null returns an empty buffer.

verifyPaddingback to summary
public static void verifyPadding(int padding)
writeFrameHeaderback to summary
public static void writeFrameHeader(Buffer out, int payloadLength, byte type, Http2Flags flags, int streamId)

Writes an HTTP/2 frame header to the output buffer.

writeFrameHeaderInternalback to summary
pack-priv static void writeFrameHeaderInternal(Buffer out, int payloadLength, byte type, Http2Flags flags, int streamId)
io.netty5.handler.codec.http2 back to summary

pack-priv final Class Http2CodecUtil.SimpleChannelPromiseAggregator

extends DefaultPromise<Void>
Class Inheritance

Provides the ability to associate the outcome of multiple Promise objects into a single Promise object.

Field Summary

Modifier and TypeField and Description
private Throwable
private boolean
private int
private int
private final Promise<Void>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private boolean
private boolean
private boolean
public Future<Void>

Returns:

The Future that is the aggregation of all promises allocated with newPromise().
doneAllocatingPromises
()

Signify that no more newPromise() allocations will be made.

public Promise<Void>

Returns:

A new promise which will be aggregated. null if doneAllocatingPromises() was previously called.
newPromise
()

Allocate a new promise which will be used to aggregate the overall success of this promise aggregator.

private void
public Promise<Void>
setFailure(Throwable cause)

Overrides io.netty5.util.concurrent.DefaultPromise.setFailure.

Implements io.netty5.util.concurrent.Promise.setFailure.

Fail this object if it has not already been failed.
private Promise<Void>
public Promise<Void>
setSuccess(Void result)

Overrides io.netty5.util.concurrent.DefaultPromise.setSuccess.

Implements io.netty5.util.concurrent.Promise.setSuccess.

Marks this promise as a success and notifies all listeners attached to the future.
public boolean
tryFailure(Throwable cause)

Overrides io.netty5.util.concurrent.DefaultPromise.tryFailure.

Implements io.netty5.util.concurrent.Promise.tryFailure.

Marks this promise as a failure and notifies all listeners.
private boolean
public boolean
trySuccess(Void result)

Overrides io.netty5.util.concurrent.DefaultPromise.trySuccess.

Implements io.netty5.util.concurrent.Promise.trySuccess.

Marks this future as a success and notifies all listeners.
Inherited from io.netty5.util.concurrent.DefaultPromise:
acceptEitheracceptEitherAsyncacceptEitherAsyncaddListeneraddListenerapplyToEitherapplyToEitherAsyncapplyToEitherAsyncasFutureasStageawaitawaitcancelcancelcausecheckDeadLockcheckDeadLockexceptionallyexecutorfuturegetgetgetNowhandlehandleAsynchandleAsyncisCancellableisCancelledisDoneisFailedisSuccessrunAfterBothrunAfterBothAsyncrunAfterBothAsyncrunAfterEitherrunAfterEitherAsyncrunAfterEitherAsyncsetUncancellablesyncthenAcceptthenAcceptAsyncthenAcceptAsyncthenAcceptBoththenAcceptBothAsyncthenAcceptBothAsyncthenApplythenApplyAsyncthenApplyAsyncthenCombinethenCombineAsyncthenCombineAsyncthenComposethenComposeAsyncthenComposeAsyncthenRunthenRunAsyncthenRunAsynctoStringtoStringBuilderwhenCompletewhenCompleteAsyncwhenCompleteAsync

Field Detail

aggregateFailureback to summary
private Throwable aggregateFailure
doneAllocatingback to summary
private boolean doneAllocating
doneCountback to summary
private int doneCount
expectedCountback to summary
private int expectedCount
promiseback to summary
private final Promise<Void> promise

Constructor Detail

SimpleChannelPromiseAggregatorback to summary
pack-priv SimpleChannelPromiseAggregator(Promise<Void> promise, EventExecutor e)

Method Detail

allowFailureback to summary
private boolean allowFailure()
allPromisesDoneback to summary
private boolean allPromisesDone()
awaitingPromisesback to summary
private boolean awaitingPromises()
doneAllocatingPromisesback to summary
public Future<Void> doneAllocatingPromises()

Signify that no more newPromise() allocations will be made. The aggregation can not be successful until this method is called.

Returns:Future<Void>

The Future that is the aggregation of all promises allocated with newPromise().

newPromiseback to summary
public Promise<Void> newPromise()

Allocate a new promise which will be used to aggregate the overall success of this promise aggregator.

Returns:Promise<Void>

A new promise which will be aggregated. null if doneAllocatingPromises() was previously called.

setAggregateFailureback to summary
private void setAggregateFailure(Throwable cause)
setFailureback to summary
public Promise<Void> setFailure(Throwable cause)

Overrides io.netty5.util.concurrent.DefaultPromise.setFailure.

Implements io.netty5.util.concurrent.Promise.setFailure.

Fail this object if it has not already been failed.

This method will NOT throw an IllegalStateException if called multiple times because that may be expected.

Annotations
@Override
setPromiseback to summary
private Promise<Void> setPromise()
setSuccessback to summary
public Promise<Void> setSuccess(Void result)

Overrides io.netty5.util.concurrent.DefaultPromise.setSuccess.

Implements io.netty5.util.concurrent.Promise.setSuccess.

Doc from io.netty5.util.concurrent.Promise.setSuccess.

Marks this promise as a success and notifies all listeners attached to the future.

If it is success or failed already it will throw an IllegalStateException.

Annotations
@Override
tryFailureback to summary
public boolean tryFailure(Throwable cause)

Overrides io.netty5.util.concurrent.DefaultPromise.tryFailure.

Implements io.netty5.util.concurrent.Promise.tryFailure.

Doc from io.netty5.util.concurrent.Promise.tryFailure.

Marks this promise as a failure and notifies all listeners.

Returns:boolean

true if and only if successfully marked this promise as a failure. Otherwise false because this promise is already marked as either a success or a failure.

Annotations
@Override
tryPromiseback to summary
private boolean tryPromise()
trySuccessback to summary
public boolean trySuccess(Void result)

Overrides io.netty5.util.concurrent.DefaultPromise.trySuccess.

Implements io.netty5.util.concurrent.Promise.trySuccess.

Doc from io.netty5.util.concurrent.Promise.trySuccess.

Marks this future as a success and notifies all listeners.

Returns:boolean

true if and only if successfully marked this promise as a success. Otherwise false because this promise is already marked as either a success or a failure.

Annotations
@Override