Class DelegatingDecompressorFrameListener
java.lang.Object
io.netty.handler.codec.http2.Http2FrameListenerDecorator
io.netty.handler.codec.http2.DelegatingDecompressorFrameListener
- All Implemented Interfaces:
Http2FrameListener
An HTTP2 frame listener that will decompress data frames according to the
content-encoding header for each
stream. The decompression provided by this class will be applied to the data for the entire stream.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classA decorator around the local flow controller that converts consumed bytes from uncompressed to compressed.private static final classProvides the state for streamDATAframe decompression. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Http2Connectionprivate booleanprivate final intprivate final Http2Connection.PropertyKeyprivate final booleanFields inherited from class Http2FrameListenerDecorator
listener -
Constructor Summary
ConstructorsConstructorDescriptionDelegatingDecompressorFrameListener(Http2Connection connection, Http2FrameListener listener) Deprecated.DelegatingDecompressorFrameListener(Http2Connection connection, Http2FrameListener listener, boolean strict) DelegatingDecompressorFrameListener(Http2Connection connection, Http2FrameListener listener, boolean strict, int maxAllocation) Create a new instance.DelegatingDecompressorFrameListener(Http2Connection connection, Http2FrameListener listener, int maxAllocation) Create a new instance. -
Method Summary
Modifier and TypeMethodDescription(package private) DelegatingDecompressorFrameListener.Http2Decompressordecompressor(Http2Stream stream) protected CharSequencegetTargetContentEncoding(CharSequence contentEncoding) Returns the expected content encoding of the decoded content.private voidinitDecompressor(ChannelHandlerContext ctx, int streamId, Http2Headers headers, boolean endOfStream) Checks if a new decompressor object is needed for the stream identified bystreamId.protected EmbeddedChannelnewContentDecompressor(ChannelHandlerContext ctx, CharSequence contentEncoding) Returns a newEmbeddedChannelthat decodes the HTTP2 message content encoded in the specifiedcontentEncoding.intonDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream) Handles an inboundDATAframe.voidonHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endStream) Handles an inboundHEADERSframe.voidonHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) Handles an inboundHEADERSframe with priority information specified.Methods inherited from class Http2FrameListenerDecorator
onGoAwayRead, onPingAckRead, onPingRead, onPriorityRead, onPushPromiseRead, onRstStreamRead, onSettingsAckRead, onSettingsRead, onUnknownFrame, onWindowUpdateRead
-
Field Details
-
connection
-
strict
private final boolean strict -
flowControllerInitialized
private boolean flowControllerInitialized -
propertyKey
-
maxAllocation
private final int maxAllocation
-
-
Constructor Details
-
DelegatingDecompressorFrameListener
@Deprecated public DelegatingDecompressorFrameListener(Http2Connection connection, Http2FrameListener listener) Create a new instance.- Parameters:
connection- the connection to read data which should be decompressedlistener- the delegate listener used byHttp2FrameListenerDecorator
-
DelegatingDecompressorFrameListener
public DelegatingDecompressorFrameListener(Http2Connection connection, Http2FrameListener listener, int maxAllocation) Create a new instance.- Parameters:
connection- the connection to read data which should be decompressedlistener- the delegate listener used byHttp2FrameListenerDecoratormaxAllocation- maximum size of the decompression buffer. Must be >= 0. If zero, maximum size is not limited by decoder.
-
DelegatingDecompressorFrameListener
@Deprecated public DelegatingDecompressorFrameListener(Http2Connection connection, Http2FrameListener listener, boolean strict) Deprecated.Create a new instance.- Parameters:
connection- the connection to read data which should be decompressedlistener- the delegate listener used byHttp2FrameListenerDecoratorstrict- if `true`,ZlibWrapper.ZLIBwill be used for the decoder, otherwise the decoder can fallback toZlibWrapper.NONE
-
DelegatingDecompressorFrameListener
public DelegatingDecompressorFrameListener(Http2Connection connection, Http2FrameListener listener, boolean strict, int maxAllocation) Create a new instance.- Parameters:
connection- the connection to read data which should be decompressedlistener- the delegate listener used byHttp2FrameListenerDecoratorstrict- if `true`,ZlibWrapper.ZLIBwill be used for the decoder, otherwise the decoder can fallback toZlibWrapper.NONEmaxAllocation- maximum size of the decompression buffer. Must be >= 0. If zero, maximum size is not limited by decoder.
-
-
Method Details
-
onDataRead
public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream) throws Http2Exception Description copied from interface:Http2FrameListenerHandles an inboundDATAframe.- Specified by:
onDataReadin interfaceHttp2FrameListener- Overrides:
onDataReadin classHttp2FrameListenerDecorator- Parameters:
ctx- the context from the handler where the frame was read.streamId- the subject stream for the frame.data- payload buffer for the frame. This buffer will be released by the codec.padding- additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).endOfStream- Indicates whether this is the last frame to be sent from the remote endpoint for this stream.- Returns:
- the number of bytes that have been processed by the application. The returned bytes are used by the
inbound flow controller to determine the appropriate time to expand the inbound flow control window (i.e. send
WINDOW_UPDATE). Returning a value equal to the length ofdata+paddingwill effectively opt-out of application-level flow control for this frame. Returning a value less than the length ofdata+paddingwill defer the returning of the processed bytes, which the application must later return viaHttp2LocalFlowController.consumeBytes(Http2Stream, int). The returned value must be >=0and invalid input: '<'=data.readableBytes()+padding. - Throws:
Http2Exception
-
onHeadersRead
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endStream) throws Http2Exception Description copied from interface:Http2FrameListenerHandles an inboundHEADERSframe.Only one of the following methods will be called for each
HEADERSframe sequence. One will be called when theEND_HEADERSflag has been received.Http2FrameListener.onHeadersRead(ChannelHandlerContext, int, Http2Headers, int, boolean)Http2FrameListener.onHeadersRead(ChannelHandlerContext, int, Http2Headers, int, short, boolean, int, boolean)Http2FrameListener.onPushPromiseRead(ChannelHandlerContext, int, int, Http2Headers, int)
To say it another way; the
Http2Headerswill contain all of the headers for the current message exchange step (additional queuing is not necessary).- Specified by:
onHeadersReadin interfaceHttp2FrameListener- Overrides:
onHeadersReadin classHttp2FrameListenerDecorator- Parameters:
ctx- the context from the handler where the frame was read.streamId- the subject stream for the frame.headers- the received headers.padding- additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).endStream- Indicates whether this is the last frame to be sent from the remote endpoint for this stream.- Throws:
Http2Exception
-
onHeadersRead
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception Description copied from interface:Http2FrameListenerHandles an inboundHEADERSframe with priority information specified. Only called ifEND_HEADERSencountered.Only one of the following methods will be called for each
HEADERSframe sequence. One will be called when theEND_HEADERSflag has been received.Http2FrameListener.onHeadersRead(ChannelHandlerContext, int, Http2Headers, int, boolean)Http2FrameListener.onHeadersRead(ChannelHandlerContext, int, Http2Headers, int, short, boolean, int, boolean)Http2FrameListener.onPushPromiseRead(ChannelHandlerContext, int, int, Http2Headers, int)
To say it another way; the
Http2Headerswill contain all of the headers for the current message exchange step (additional queuing is not necessary).- Specified by:
onHeadersReadin interfaceHttp2FrameListener- Overrides:
onHeadersReadin classHttp2FrameListenerDecorator- Parameters:
ctx- the context from the handler where the frame was read.streamId- the subject stream for the frame.headers- the received headers.streamDependency- the stream on which this stream depends, or 0 if dependent on the connection.weight- the new weight for the stream.exclusive- whether or not the stream should be the exclusive dependent of its parent.padding- additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).endStream- Indicates whether this is the last frame to be sent from the remote endpoint for this stream.- Throws:
Http2Exception
-
newContentDecompressor
protected EmbeddedChannel newContentDecompressor(ChannelHandlerContext ctx, CharSequence contentEncoding) throws Http2Exception Returns a newEmbeddedChannelthat decodes the HTTP2 message content encoded in the specifiedcontentEncoding.- Parameters:
contentEncoding- the value of thecontent-encodingheader- Returns:
- a new
ByteToMessageDecoderif the specified encoding is supported.nullotherwise (alternatively, you can throw aHttp2Exceptionto block unknown encoding). - Throws:
Http2Exception- If the specified encoding is not supported and warrants an exception
-
getTargetContentEncoding
Returns the expected content encoding of the decoded content. This getMethod returns"identity"by default, which is the case for most decompressors.- Parameters:
contentEncoding- the value of thecontent-encodingheader- Returns:
- the expected content encoding of the new content.
- Throws:
Http2Exception- if thecontentEncodingis not supported and warrants an exception
-
initDecompressor
private void initDecompressor(ChannelHandlerContext ctx, int streamId, Http2Headers headers, boolean endOfStream) throws Http2Exception Checks if a new decompressor object is needed for the stream identified bystreamId. This method will modify thecontent-encodingheader contained inheaders.- Parameters:
ctx- The contextstreamId- The identifier for the headers insideheadersheaders- Object representing headers which have been readendOfStream- Indicates if the stream has ended- Throws:
Http2Exception- If thecontent-encodingis not supported
-
decompressor
-
DelegatingDecompressorFrameListener(Http2Connection, Http2FrameListener, int)