Package io.netty.handler.codec.http2
Class DefaultHttp2FrameReader
- java.lang.Object
-
- io.netty.handler.codec.http2.DefaultHttp2FrameReader
-
- All Implemented Interfaces:
Http2FrameReader
,Http2FrameReader.Configuration
,Http2FrameSizePolicy
,java.io.Closeable
,java.lang.AutoCloseable
@UnstableApi public class DefaultHttp2FrameReader extends java.lang.Object implements Http2FrameReader, Http2FrameSizePolicy, Http2FrameReader.Configuration
AHttp2FrameReader
that supports all frame types defined by the HTTP/2 specification.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
DefaultHttp2FrameReader.HeadersBlockBuilder
Utility class to help with construction of the headers block that may potentially span multiple frames.private class
DefaultHttp2FrameReader.HeadersContinuation
Base class for processing of HEADERS and PUSH_PROMISE header blocks that potentially span multiple frames.-
Nested classes/interfaces inherited from interface io.netty.handler.codec.http2.Http2FrameReader
Http2FrameReader.Configuration
-
-
Field Summary
Fields Modifier and Type Field Description private Http2Flags
flags
private byte
frameType
private DefaultHttp2FrameReader.HeadersContinuation
headersContinuation
private Http2HeadersDecoder
headersDecoder
private int
maxFrameSize
private int
payloadLength
private boolean
readError
Once set totrue
the value will never change.private boolean
readingHeaders
true
= reading headers,false
= reading payload.private int
streamId
-
Constructor Summary
Constructors Constructor Description DefaultHttp2FrameReader()
Create a new instance.DefaultHttp2FrameReader(boolean validateHeaders)
Create a new instance.DefaultHttp2FrameReader(Http2HeadersDecoder headersDecoder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes this reader and frees any allocated resources.private void
closeHeadersContinuation()
Http2FrameReader.Configuration
configuration()
Get the configuration related elements for thisHttp2FrameReader
Http2FrameSizePolicy
frameSizePolicy()
Get theHttp2FrameSizePolicy
for thisHttp2FrameReader
Http2HeadersDecoder.Configuration
headersConfiguration()
Get theHttp2HeadersDecoder.Configuration
for thisHttp2FrameReader
private static int
lengthWithoutTrailingPadding(int readableBytes, int padding)
The padding parameter consists of the 1 byte pad length field and the trailing padding bytes.int
maxFrameSize()
Gets the maximum allowed frame size.void
maxFrameSize(int max)
Sets the maximum allowed frame size.private boolean
preProcessFrame(ByteBuf in)
private void
processPayloadState(ChannelHandlerContext ctx, ByteBuf in, Http2FrameListener listener)
private void
readContinuationFrame(ByteBuf payload, Http2FrameListener listener)
private void
readDataFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener)
void
readFrame(ChannelHandlerContext ctx, ByteBuf input, Http2FrameListener listener)
Attempts to read the next frame from the input buffer.private void
readGoAwayFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener)
private void
readHeadersFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener)
private int
readPadding(ByteBuf payload)
If padding is present in the payload, reads the next byte as padding.private void
readPingFrame(ChannelHandlerContext ctx, long data, Http2FrameListener listener)
private void
readPriorityFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener)
private void
readPushPromiseFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener)
private void
readRstStreamFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener)
private void
readSettingsFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener)
private void
readUnknownFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener)
private void
readWindowUpdateFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener)
private void
resetHeadersContinuationIfEnd(boolean endOfHeaders)
private void
verifyAssociatedWithAStream()
private void
verifyContinuationFrame()
private void
verifyDataFrame()
private void
verifyFrameState()
private void
verifyGoAwayFrame()
private void
verifyHeadersFrame()
private void
verifyNotProcessingHeaders()
Verify that current state is not processing on header blockprivate void
verifyPadding(int padding)
private void
verifyPingFrame()
private void
verifyPriorityFrame()
private void
verifyPushPromiseFrame()
private void
verifyRstStreamFrame()
private void
verifySettingsFrame()
private static void
verifyStreamOrConnectionId(int streamId, java.lang.String argumentName)
private void
verifyUnknownFrame()
private void
verifyWindowUpdateFrame()
-
-
-
Field Detail
-
headersDecoder
private final Http2HeadersDecoder headersDecoder
-
readingHeaders
private boolean readingHeaders
true
= reading headers,false
= reading payload.
-
readError
private boolean readError
Once set totrue
the value will never change. This is set totrue
if an unrecoverable error which renders the connection unusable.
-
frameType
private byte frameType
-
streamId
private int streamId
-
flags
private Http2Flags flags
-
payloadLength
private int payloadLength
-
headersContinuation
private DefaultHttp2FrameReader.HeadersContinuation headersContinuation
-
maxFrameSize
private int maxFrameSize
-
-
Constructor Detail
-
DefaultHttp2FrameReader
public DefaultHttp2FrameReader()
Create a new instance.Header names will be validated.
-
DefaultHttp2FrameReader
public DefaultHttp2FrameReader(boolean validateHeaders)
Create a new instance.- Parameters:
validateHeaders
-true
to validate headers.false
to not validate headers.- See Also:
DefaultHttp2HeadersDecoder(boolean)
-
DefaultHttp2FrameReader
public DefaultHttp2FrameReader(Http2HeadersDecoder headersDecoder)
-
-
Method Detail
-
headersConfiguration
public Http2HeadersDecoder.Configuration headersConfiguration()
Description copied from interface:Http2FrameReader.Configuration
Get theHttp2HeadersDecoder.Configuration
for thisHttp2FrameReader
- Specified by:
headersConfiguration
in interfaceHttp2FrameReader.Configuration
-
configuration
public Http2FrameReader.Configuration configuration()
Description copied from interface:Http2FrameReader
Get the configuration related elements for thisHttp2FrameReader
- Specified by:
configuration
in interfaceHttp2FrameReader
-
frameSizePolicy
public Http2FrameSizePolicy frameSizePolicy()
Description copied from interface:Http2FrameReader.Configuration
Get theHttp2FrameSizePolicy
for thisHttp2FrameReader
- Specified by:
frameSizePolicy
in interfaceHttp2FrameReader.Configuration
-
maxFrameSize
public void maxFrameSize(int max) throws Http2Exception
Description copied from interface:Http2FrameSizePolicy
Sets the maximum allowed frame size. Attempts to write frames longer than this maximum will fail.This value is used to represent SETTINGS_MAX_FRAME_SIZE. This method should only be called by Netty (not users) as a result of a receiving a
SETTINGS
frame.- Specified by:
maxFrameSize
in interfaceHttp2FrameSizePolicy
- Throws:
Http2Exception
-
maxFrameSize
public int maxFrameSize()
Description copied from interface:Http2FrameSizePolicy
Gets the maximum allowed frame size.This value is used to represent SETTINGS_MAX_FRAME_SIZE. The initial value defined by the RFC is unlimited but enforcing a lower limit is generally permitted.
Http2CodecUtil.DEFAULT_MAX_FRAME_SIZE
can be used as a more conservative default.- Specified by:
maxFrameSize
in interfaceHttp2FrameSizePolicy
-
close
public void close()
Description copied from interface:Http2FrameReader
Closes this reader and frees any allocated resources.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceHttp2FrameReader
-
closeHeadersContinuation
private void closeHeadersContinuation()
-
readFrame
public void readFrame(ChannelHandlerContext ctx, ByteBuf input, Http2FrameListener listener) throws Http2Exception
Description copied from interface:Http2FrameReader
Attempts to read the next frame from the input buffer. If enough data is available to fully read the frame, notifies the listener of the read frame.- Specified by:
readFrame
in interfaceHttp2FrameReader
- Throws:
Http2Exception
-
preProcessFrame
private boolean preProcessFrame(ByteBuf in) throws Http2Exception
- Throws:
Http2Exception
-
verifyFrameState
private void verifyFrameState() throws Http2Exception
- Throws:
Http2Exception
-
processPayloadState
private void processPayloadState(ChannelHandlerContext ctx, ByteBuf in, Http2FrameListener listener) throws Http2Exception
- Throws:
Http2Exception
-
verifyDataFrame
private void verifyDataFrame() throws Http2Exception
- Throws:
Http2Exception
-
verifyHeadersFrame
private void verifyHeadersFrame() throws Http2Exception
- Throws:
Http2Exception
-
verifyPriorityFrame
private void verifyPriorityFrame() throws Http2Exception
- Throws:
Http2Exception
-
verifyRstStreamFrame
private void verifyRstStreamFrame() throws Http2Exception
- Throws:
Http2Exception
-
verifySettingsFrame
private void verifySettingsFrame() throws Http2Exception
- Throws:
Http2Exception
-
verifyPushPromiseFrame
private void verifyPushPromiseFrame() throws Http2Exception
- Throws:
Http2Exception
-
verifyPingFrame
private void verifyPingFrame() throws Http2Exception
- Throws:
Http2Exception
-
verifyGoAwayFrame
private void verifyGoAwayFrame() throws Http2Exception
- Throws:
Http2Exception
-
verifyWindowUpdateFrame
private void verifyWindowUpdateFrame() throws Http2Exception
- Throws:
Http2Exception
-
verifyContinuationFrame
private void verifyContinuationFrame() throws Http2Exception
- Throws:
Http2Exception
-
verifyUnknownFrame
private void verifyUnknownFrame() throws Http2Exception
- Throws:
Http2Exception
-
readDataFrame
private void readDataFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener) throws Http2Exception
- Throws:
Http2Exception
-
readHeadersFrame
private void readHeadersFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener) throws Http2Exception
- Throws:
Http2Exception
-
resetHeadersContinuationIfEnd
private void resetHeadersContinuationIfEnd(boolean endOfHeaders)
-
readPriorityFrame
private void readPriorityFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener) throws Http2Exception
- Throws:
Http2Exception
-
readRstStreamFrame
private void readRstStreamFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener) throws Http2Exception
- Throws:
Http2Exception
-
readSettingsFrame
private void readSettingsFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener) throws Http2Exception
- Throws:
Http2Exception
-
readPushPromiseFrame
private void readPushPromiseFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener) throws Http2Exception
- Throws:
Http2Exception
-
readPingFrame
private void readPingFrame(ChannelHandlerContext ctx, long data, Http2FrameListener listener) throws Http2Exception
- Throws:
Http2Exception
-
readGoAwayFrame
private void readGoAwayFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener) throws Http2Exception
- Throws:
Http2Exception
-
readWindowUpdateFrame
private void readWindowUpdateFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener) throws Http2Exception
- Throws:
Http2Exception
-
readContinuationFrame
private void readContinuationFrame(ByteBuf payload, Http2FrameListener listener) throws Http2Exception
- Throws:
Http2Exception
-
readUnknownFrame
private void readUnknownFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener) throws Http2Exception
- Throws:
Http2Exception
-
readPadding
private int readPadding(ByteBuf payload)
If padding is present in the payload, reads the next byte as padding. The padding also includes the one byte width of the pad length field. Otherwise, returns zero.
-
verifyPadding
private void verifyPadding(int padding) throws Http2Exception
- Throws:
Http2Exception
-
lengthWithoutTrailingPadding
private static int lengthWithoutTrailingPadding(int readableBytes, int padding)
The padding parameter consists of the 1 byte pad length field and the trailing padding bytes. This method returns the number of readable bytes without the trailing padding.
-
verifyNotProcessingHeaders
private void verifyNotProcessingHeaders() throws Http2Exception
Verify that current state is not processing on header block- Throws:
Http2Exception
- thrown ifheadersContinuation
is not null
-
verifyAssociatedWithAStream
private void verifyAssociatedWithAStream() throws Http2Exception
- Throws:
Http2Exception
-
verifyStreamOrConnectionId
private static void verifyStreamOrConnectionId(int streamId, java.lang.String argumentName) throws Http2Exception
- Throws:
Http2Exception
-
-