Class Http2CodecUtil

java.lang.Object
io.netty.handler.codec.http2.Http2CodecUtil

@UnstableApi public final class Http2CodecUtil extends Object
Constants and utility method used for encoding/decoding HTTP2 frames.
  • 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

      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:
    • MAX_UNSIGNED_BYTE

      public static final short MAX_UNSIGNED_BYTE
      See Also:
    • 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:
    • 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

      private static final ByteBuf 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:
    • 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_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.
      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_STREAMS
      The assumed minimum value for SETTINGS_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 a GO_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)
      Returns true 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 the streamId 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

      public static ByteBuf connectionPrefaceBuf()
      Returns a buffer containing the CONNECTION_PREFACE.
    • getEmbeddedHttp2Exception

      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.
    • toByteBuf

      public static ByteBuf toByteBuf(ChannelHandlerContext ctx, Throwable cause)
      Creates a buffer containing the error message from the given exception. If the cause is null returns an empty buffer.
    • readUnsignedInt

      public static int readUnsignedInt(ByteBuf buf)
      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

      public static int streamableBytes(StreamByteDistributor.StreamState state)
      Calculate the amount of bytes that can be sent by state. The lower bound is 0.
    • headerListSizeExceeded

      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 - 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.
    • writeFrameHeaderInternal

      static void writeFrameHeaderInternal(ByteBuf out, int payloadLength, byte type, Http2Flags flags, int streamId)
    • verifyPadding

      public static void verifyPadding(int padding)