@UnstableApi public class DelegatingDecompressorFrameListener extends Http2FrameListenerDecorator
content-encoding
header for each
stream. The decompression provided by this class will be applied to the data for the entire stream.Modifier and Type | Class and Description |
---|---|
private class |
DelegatingDecompressorFrameListener.ConsumedBytesConverter
A decorator around the local flow controller that converts consumed bytes from uncompressed to compressed.
|
private static class |
DelegatingDecompressorFrameListener.Http2Decompressor
Provides the state for stream
DATA frame decompression. |
Modifier and Type | Field and Description |
---|---|
private Http2Connection |
connection |
private boolean |
flowControllerInitialized |
private Http2Connection.PropertyKey |
propertyKey |
private boolean |
strict |
listener
Constructor and Description |
---|
DelegatingDecompressorFrameListener(Http2Connection connection,
Http2FrameListener listener) |
DelegatingDecompressorFrameListener(Http2Connection connection,
Http2FrameListener listener,
boolean strict) |
Modifier and Type | Method and Description |
---|---|
private static void |
cleanup(DelegatingDecompressorFrameListener.Http2Decompressor decompressor)
Release remaining content from the
EmbeddedChannel . |
(package private) DelegatingDecompressorFrameListener.Http2Decompressor |
decompressor(Http2Stream stream) |
protected java.lang.CharSequence |
getTargetContentEncoding(java.lang.CharSequence contentEncoding)
Returns the expected content encoding of the decoded content.
|
private void |
initDecompressor(ChannelHandlerContext ctx,
int streamId,
Http2Headers headers,
boolean endOfStream)
Checks if a new decompressor object is needed for the stream identified by
streamId . |
protected EmbeddedChannel |
newContentDecompressor(ChannelHandlerContext ctx,
java.lang.CharSequence contentEncoding)
Returns a new
EmbeddedChannel that decodes the HTTP2 message content encoded in the specified
contentEncoding . |
private static ByteBuf |
nextReadableBuf(EmbeddedChannel decompressor)
|
int |
onDataRead(ChannelHandlerContext ctx,
int streamId,
ByteBuf data,
int padding,
boolean endOfStream)
Handles an inbound
DATA frame. |
void |
onHeadersRead(ChannelHandlerContext ctx,
int streamId,
Http2Headers headers,
int padding,
boolean endStream)
Handles an inbound
HEADERS frame. |
void |
onHeadersRead(ChannelHandlerContext ctx,
int streamId,
Http2Headers headers,
int streamDependency,
short weight,
boolean exclusive,
int padding,
boolean endStream)
Handles an inbound
HEADERS frame with priority information specified. |
onGoAwayRead, onPingAckRead, onPingRead, onPriorityRead, onPushPromiseRead, onRstStreamRead, onSettingsAckRead, onSettingsRead, onUnknownFrame, onWindowUpdateRead
private final Http2Connection connection
private final boolean strict
private boolean flowControllerInitialized
private final Http2Connection.PropertyKey propertyKey
public DelegatingDecompressorFrameListener(Http2Connection connection, Http2FrameListener listener)
public DelegatingDecompressorFrameListener(Http2Connection connection, Http2FrameListener listener, boolean strict)
public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream) throws Http2Exception
Http2FrameListener
DATA
frame.onDataRead
in interface Http2FrameListener
onDataRead
in class Http2FrameListenerDecorator
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.WINDOW_UPDATE
). Returning a value equal to the length of data
+ padding
will effectively
opt-out of application-level flow control for this frame. Returning a value less than the length of data
+ padding
will defer the returning of the processed bytes, which the application must later return via
Http2LocalFlowController.consumeBytes(Http2Stream, int)
. The returned value must
be >= 0
and <= data.readableBytes()
+ padding
.Http2Exception
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endStream) throws Http2Exception
Http2FrameListener
HEADERS
frame.
Only one of the following methods will be called for each HEADERS
frame sequence.
One will be called when the END_HEADERS
flag 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 Http2Headers
will contain all of the headers
for the current message exchange step (additional queuing is not necessary).
onHeadersRead
in interface Http2FrameListener
onHeadersRead
in class Http2FrameListenerDecorator
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.Http2Exception
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception
Http2FrameListener
HEADERS
frame with priority information specified.
Only called if END_HEADERS
encountered.
Only one of the following methods will be called for each HEADERS
frame sequence.
One will be called when the END_HEADERS
flag 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 Http2Headers
will contain all of the headers
for the current message exchange step (additional queuing is not necessary).
onHeadersRead
in interface Http2FrameListener
onHeadersRead
in class Http2FrameListenerDecorator
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.Http2Exception
protected EmbeddedChannel newContentDecompressor(ChannelHandlerContext ctx, java.lang.CharSequence contentEncoding) throws Http2Exception
EmbeddedChannel
that decodes the HTTP2 message content encoded in the specified
contentEncoding
.contentEncoding
- the value of the content-encoding
headerByteToMessageDecoder
if the specified encoding is supported. null
otherwise
(alternatively, you can throw a Http2Exception
to block unknown encoding).Http2Exception
- If the specified encoding is not not supported and warrants an exceptionprotected java.lang.CharSequence getTargetContentEncoding(java.lang.CharSequence contentEncoding) throws Http2Exception
"identity"
by
default, which is the case for most decompressors.contentEncoding
- the value of the content-encoding
headerHttp2Exception
- if the contentEncoding
is not supported and warrants an exceptionprivate void initDecompressor(ChannelHandlerContext ctx, int streamId, Http2Headers headers, boolean endOfStream) throws Http2Exception
streamId
.
This method will modify the content-encoding
header contained in headers
.ctx
- The contextstreamId
- The identifier for the headers inside headers
headers
- Object representing headers which have been readendOfStream
- Indicates if the stream has endedHttp2Exception
- If the content-encoding
is not supportedDelegatingDecompressorFrameListener.Http2Decompressor decompressor(Http2Stream stream)
private static void cleanup(DelegatingDecompressorFrameListener.Http2Decompressor decompressor)
EmbeddedChannel
.decompressor
- The decompressor for stream
private static ByteBuf nextReadableBuf(EmbeddedChannel decompressor)
decompressor
- The channel to read fromByteBuf
from the EmbeddedChannel
or null
if one does not exist