@UnstableApi public class CompressorHttp2ConnectionEncoder extends DecoratingHttp2ConnectionEncoder
content-encoding
header for each
stream. The compression provided by this class will be applied to the data for the entire stream.Http2FrameWriter.Configuration
Modifier and Type | Field and Description |
---|---|
private int |
compressionLevel |
static int |
DEFAULT_COMPRESSION_LEVEL |
static int |
DEFAULT_MEM_LEVEL |
static int |
DEFAULT_WINDOW_BITS |
private int |
memLevel |
private Http2Connection.PropertyKey |
propertyKey |
private int |
windowBits |
Constructor and Description |
---|
CompressorHttp2ConnectionEncoder(Http2ConnectionEncoder delegate) |
CompressorHttp2ConnectionEncoder(Http2ConnectionEncoder delegate,
int compressionLevel,
int windowBits,
int memLevel) |
Modifier and Type | Method and Description |
---|---|
private void |
bindCompressorToStream(EmbeddedChannel compressor,
int streamId)
Called after the super class has written the headers and created any associated stream objects.
|
(package private) void |
cleanup(Http2Stream stream,
EmbeddedChannel compressor)
Release remaining content from
EmbeddedChannel and remove the compressor from the Http2Stream . |
protected java.lang.CharSequence |
getTargetContentEncoding(java.lang.CharSequence contentEncoding)
Returns the expected content encoding of the decoded content.
|
private EmbeddedChannel |
newCompressionChannel(ChannelHandlerContext ctx,
ZlibWrapper wrapper)
Generate a new instance of an
EmbeddedChannel capable of compressing data |
private EmbeddedChannel |
newCompressor(ChannelHandlerContext ctx,
Http2Headers headers,
boolean endOfStream)
Checks if a new compressor object is needed for the stream identified by
streamId . |
protected EmbeddedChannel |
newContentCompressor(ChannelHandlerContext ctx,
java.lang.CharSequence contentEncoding)
Returns a new
EmbeddedChannel that encodes the HTTP2 message content encoded in the specified
contentEncoding . |
private static ByteBuf |
nextReadableBuf(EmbeddedChannel compressor)
|
ChannelFuture |
writeData(ChannelHandlerContext ctx,
int streamId,
ByteBuf data,
int padding,
boolean endOfStream,
ChannelPromise promise)
Writes a
DATA frame to the remote endpoint. |
ChannelFuture |
writeHeaders(ChannelHandlerContext ctx,
int streamId,
Http2Headers headers,
int padding,
boolean endStream,
ChannelPromise promise)
Writes a HEADERS frame to the remote endpoint.
|
ChannelFuture |
writeHeaders(ChannelHandlerContext ctx,
int streamId,
Http2Headers headers,
int streamDependency,
short weight,
boolean exclusive,
int padding,
boolean endOfStream,
ChannelPromise promise)
Writes a HEADERS frame with priority specified to the remote endpoint.
|
connection, flowController, frameWriter, lifecycleManager, pollSentSettings, remoteSettings
close, configuration, writeFrame, writeGoAway, writePing, writePriority, writePushPromise, writeRstStream, writeSettings, writeSettingsAck, writeWindowUpdate
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
writeFrame
close, configuration, writeGoAway, writePing, writePriority, writePushPromise, writeRstStream, writeSettings, writeSettingsAck, writeWindowUpdate
public static final int DEFAULT_COMPRESSION_LEVEL
public static final int DEFAULT_WINDOW_BITS
public static final int DEFAULT_MEM_LEVEL
private final int compressionLevel
private final int windowBits
private final int memLevel
private final Http2Connection.PropertyKey propertyKey
public CompressorHttp2ConnectionEncoder(Http2ConnectionEncoder delegate)
public CompressorHttp2ConnectionEncoder(Http2ConnectionEncoder delegate, int compressionLevel, int windowBits, int memLevel)
public ChannelFuture writeData(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream, ChannelPromise promise)
Http2DataWriter
DATA
frame to the remote endpoint. This will result in one or more
frames being written to the context.writeData
in interface Http2DataWriter
writeData
in class DecoratingHttp2FrameWriter
ctx
- the context to use for writing.streamId
- the stream for which to send the frame.data
- the payload of the frame. This will be released by this method.padding
- additional bytes that should be added to obscure the true content size. Must be between 0 and
256 (inclusive). A 1 byte padding is encoded as just the pad length field with value 0.
A 256 byte padding is encoded as the pad length field with value 255 and 255 padding bytes
appended to the end of the frame.endOfStream
- indicates if this is the last frame to be sent for the stream.promise
- the promise for the write.public ChannelFuture writeHeaders(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endStream, ChannelPromise promise)
Http2FrameWriter
writeHeaders
in interface Http2FrameWriter
writeHeaders
in class DecoratingHttp2FrameWriter
ctx
- the context to use for writing.streamId
- the stream for which to send the frame.headers
- the headers to be sent.padding
- additional bytes that should be added to obscure the true content size. Must be between 0 and
256 (inclusive).endStream
- indicates if this is the last frame to be sent for the stream.promise
- the promise for the write.The header block MUST be processed to ensure a consistent connection state, unless the connection is closed.If this call has modified the HPACK header state you MUST throw a connection error.
If this call has NOT modified the HPACK header state you are free to throw a stream error.
public ChannelFuture writeHeaders(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endOfStream, ChannelPromise promise)
Http2FrameWriter
writeHeaders
in interface Http2FrameWriter
writeHeaders
in class DecoratingHttp2FrameWriter
ctx
- the context to use for writing.streamId
- the stream for which to send the frame.headers
- the headers to be sent.streamDependency
- the stream on which this stream should depend, or 0 if it should
depend on the connection.weight
- the weight for this stream.exclusive
- whether this stream should be the exclusive dependant of its parent.padding
- additional bytes that should be added to obscure the true content size. Must be between 0 and
256 (inclusive).endOfStream
- indicates if this is the last frame to be sent for the stream.promise
- the promise for the write.The header block MUST be processed to ensure a consistent connection state, unless the connection is closed.If this call has modified the HPACK header state you MUST throw a connection error.
If this call has NOT modified the HPACK header state you are free to throw a stream error.
protected EmbeddedChannel newContentCompressor(ChannelHandlerContext ctx, java.lang.CharSequence contentEncoding) throws Http2Exception
EmbeddedChannel
that encodes the HTTP2 message content encoded in the specified
contentEncoding
.ctx
- the context.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
contentEncoding
is the default
behavior, which is the case for most compressors.contentEncoding
- the value of the content-encoding
headerHttp2Exception
- if the contentEncoding
is not supported and warrants an exceptionprivate EmbeddedChannel newCompressionChannel(ChannelHandlerContext ctx, ZlibWrapper wrapper)
EmbeddedChannel
capable of compressing datactx
- the context.wrapper
- Defines what type of encoder should be usedprivate EmbeddedChannel newCompressor(ChannelHandlerContext ctx, Http2Headers headers, boolean endOfStream) throws Http2Exception
streamId
. This method will
modify the content-encoding
header contained in headers
.ctx
- the context.headers
- Object representing headers which are to be writtenendOfStream
- Indicates if the stream has endedHttp2Exception
- if any problems occur during initialization.private void bindCompressorToStream(EmbeddedChannel compressor, int streamId)
compressor
- The compressor associated with the stream identified by streamId
.streamId
- The stream id for which the headers were written.void cleanup(Http2Stream stream, EmbeddedChannel compressor)
EmbeddedChannel
and remove the compressor from the Http2Stream
.stream
- The stream for which compressor
is the compressor forcompressor
- The compressor for stream
private static ByteBuf nextReadableBuf(EmbeddedChannel compressor)
compressor
- The channel to read fromByteBuf
from the EmbeddedChannel
or null
if one does not exist