Top Description Fields Constructors Methods
io.netty.handler.codec.http2

public Class CompressorHttp2ConnectionEncoder

extends DecoratingHttp2ConnectionEncoder
Class Inheritance
Annotations
@UnstableApi
Imports
io.netty.buffer.ByteBuf, .Unpooled, io.netty.channel.ChannelFuture, .ChannelHandlerContext, .ChannelPromise, io.netty.channel.embedded.EmbeddedChannel, io.netty.handler.codec.ByteToMessageDecoder, io.netty.handler.codec.compression.BrotliEncoder, .ZlibCodecFactory, .ZlibWrapper, .Brotli, .BrotliOptions, .CompressionOptions, .DeflateOptions, .GzipOptions, .StandardCompressionOptions, .ZstdEncoder, .ZstdOptions, .SnappyFrameEncoder, .SnappyOptions, io.netty.util.concurrent.PromiseCombiner, io.netty.util.internal.ObjectUtil, .UnstableApi

A decorating HTTP2 encoder that will compress data frames according to the content-encoding header for each stream. The compression provided by this class will be applied to the data for the entire stream.

Field Summary

Modifier and TypeField and Description
private BrotliOptions
private int
public static final int
public static final int
public static final int
private DeflateOptions
private GzipOptions
private int
private final Http2Connection.PropertyKey
private SnappyOptions
private final boolean
private int
private ZstdOptions

Constructor Summary

AccessConstructor and Description
public
public
CompressorHttp2ConnectionEncoder(Http2ConnectionEncoder delegate, int compressionLevel, int windowBits, int memLevel)

Deprecated
Create a new CompressorHttp2ConnectionEncoder instance
public

Method Summary

Modifier and TypeMethod and Description
private void
bindCompressorToStream(EmbeddedChannel
The compressor associated with the stream identified by streamId.
compressor
,
int
The stream id for which the headers were written.
streamId
)

Called after the super class has written the headers and created any associated stream objects.

pack-priv void
cleanup(Http2Stream
The stream for which compressor is the compressor for
stream
,
EmbeddedChannel
The compressor for stream
compressor
)

Release remaining content from EmbeddedChannel and remove the compressor from the Http2Stream.

private static CompressionOptions[]
protected CharSequence

Returns:

the expected content encoding of the new content.
getTargetContentEncoding
(CharSequence
the value of the content-encoding header
contentEncoding
)

Returns the expected content encoding of the decoded content.

private EmbeddedChannel
newCompressionChannel(final ChannelHandlerContext
the context.
ctx
,
ZlibWrapper
Defines what type of encoder should be used
wrapper
)

Generate a new instance of an EmbeddedChannel capable of compressing data

private EmbeddedChannel

Returns:

The channel used to compress data.
newCompressor
(ChannelHandlerContext
the context.
ctx
,
Http2Headers
Object representing headers which are to be written
headers
,
boolean
Indicates if the stream has ended
endOfStream
)

Checks if a new compressor object is needed for the stream identified by streamId.

protected EmbeddedChannel

Returns:

a new ByteToMessageDecoder if the specified encoding is supported. null otherwise (alternatively, you can throw a Http2Exception to block unknown encoding).
newContentCompressor
(ChannelHandlerContext
the context.
ctx
,
CharSequence
the value of the content-encoding header
contentEncoding
)

Returns a new EmbeddedChannel that encodes the HTTP2 message content encoded in the specified contentEncoding.

private static ByteBuf

Returns:

The next decoded ByteBuf from the EmbeddedChannel or null if one does not exist
nextReadableBuf
(EmbeddedChannel
The channel to read from
compressor
)

Read the next compressed ByteBuf from the EmbeddedChannel or null if one does not exist.

public ChannelFuture
writeData(final ChannelHandlerContext
the context to use for writing.
ctx
,
final int
the stream for which to send the frame.
streamId
,
ByteBuf
the payload of the frame. This will be released by this method.
data
,
int
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.
padding
,
final boolean
indicates if this is the last frame to be sent for the stream.
endOfStream
,
ChannelPromise
the promise for the write.
promise
)

Overrides io.netty.handler.codec.http2.DecoratingHttp2FrameWriter.writeData.

Implements io.netty.handler.codec.http2.Http2DataWriter.writeData.

Writes a DATA frame to the remote endpoint.
public ChannelFuture
writeHeaders(ChannelHandlerContext
the context to use for writing.
ctx
,
int
the stream for which to send the frame.
streamId
,
Http2Headers
the headers to be sent.
headers
,
int
additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).
padding
,
boolean
indicates if this is the last frame to be sent for the stream.
endStream
,
ChannelPromise
the promise for the write.
promise
)

Overrides io.netty.handler.codec.http2.DecoratingHttp2FrameWriter.writeHeaders.

Implements io.netty.handler.codec.http2.Http2FrameWriter.writeHeaders.

Writes a HEADERS frame to the remote endpoint.
public ChannelFuture
writeHeaders(final ChannelHandlerContext
the context to use for writing.
ctx
,
final int
the stream for which to send the frame.
streamId
,
final Http2Headers
the headers to be sent.
headers
,
final int
the stream on which this stream should depend, or 0 if it should depend on the connection.
streamDependency
,
final short
the weight for this stream.
weight
,
final boolean
whether this stream should be the exclusive dependant of its parent.
exclusive
,
final int
additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).
padding
,
final boolean
indicates if this is the last frame to be sent for the stream.
endOfStream
,
final ChannelPromise
the promise for the write.
promise
)

Overrides io.netty.handler.codec.http2.DecoratingHttp2FrameWriter.writeHeaders.

Implements io.netty.handler.codec.http2.Http2FrameWriter.writeHeaders.

Writes a HEADERS frame with priority specified to the remote endpoint.
Inherited from io.netty.handler.codec.http2.DecoratingHttp2ConnectionEncoder:
connectionconsumeReceivedSettingsflowControllerframeWriterlifecycleManagerpollSentSettingsremoteSettings

Field Detail

brotliOptionsback to summary
private BrotliOptions brotliOptions
compressionLevelback to summary
private int compressionLevel
DEFAULT_COMPRESSION_LEVELback to summary
public static final int DEFAULT_COMPRESSION_LEVEL
DEFAULT_MEM_LEVELback to summary
public static final int DEFAULT_MEM_LEVEL
DEFAULT_WINDOW_BITSback to summary
public static final int DEFAULT_WINDOW_BITS
deflateOptionsback to summary
private DeflateOptions deflateOptions
gzipCompressionOptionsback to summary
private GzipOptions gzipCompressionOptions
memLevelback to summary
private int memLevel
propertyKeyback to summary
private final Http2Connection.PropertyKey propertyKey
snappyOptionsback to summary
private SnappyOptions snappyOptions
supportsCompressionOptionsback to summary
private final boolean supportsCompressionOptions
windowBitsback to summary
private int windowBits
zstdOptionsback to summary
private ZstdOptions zstdOptions

Constructor Detail

CompressorHttp2ConnectionEncoderback to summary
public CompressorHttp2ConnectionEncoder(Http2ConnectionEncoder delegate)

Create a new CompressorHttp2ConnectionEncoder instance with default implementation of StandardCompressionOptions

CompressorHttp2ConnectionEncoderback to summary
public CompressorHttp2ConnectionEncoder(Http2ConnectionEncoder delegate, int compressionLevel, int windowBits, int memLevel)

Deprecated

Create a new CompressorHttp2ConnectionEncoder instance

Annotations
@Deprecated
CompressorHttp2ConnectionEncoderback to summary
public CompressorHttp2ConnectionEncoder(Http2ConnectionEncoder delegate, CompressionOptions... compressionOptionsArgs)

Create a new CompressorHttp2ConnectionEncoder with specified StandardCompressionOptions

Method Detail

bindCompressorToStreamback to summary
private void bindCompressorToStream(EmbeddedChannel compressor, int streamId)

Called after the super class has written the headers and created any associated stream objects.

Parameters
compressor:EmbeddedChannel

The compressor associated with the stream identified by streamId.

streamId:int

The stream id for which the headers were written.

cleanupback to summary
pack-priv void cleanup(Http2Stream stream, EmbeddedChannel compressor)

Release remaining content from EmbeddedChannel and remove the compressor from the Http2Stream.

Parameters
stream:Http2Stream

The stream for which compressor is the compressor for

compressor:EmbeddedChannel

The compressor for stream

defaultCompressionOptionsback to summary
private static CompressionOptions[] defaultCompressionOptions()
getTargetContentEncodingback to summary
protected CharSequence getTargetContentEncoding(CharSequence contentEncoding) throws Http2Exception

Returns the expected content encoding of the decoded content. Returning contentEncoding is the default behavior, which is the case for most compressors.

Parameters
contentEncoding:CharSequence

the value of the content-encoding header

Returns:CharSequence

the expected content encoding of the new content.

Exceptions
Http2Exception:
if the contentEncoding is not supported and warrants an exception
newCompressionChannelback to summary
private EmbeddedChannel newCompressionChannel(final ChannelHandlerContext ctx, ZlibWrapper wrapper)

Generate a new instance of an EmbeddedChannel capable of compressing data

Parameters
ctx:ChannelHandlerContext

the context.

wrapper:ZlibWrapper

Defines what type of encoder should be used

newCompressorback to summary
private EmbeddedChannel newCompressor(ChannelHandlerContext ctx, Http2Headers headers, boolean endOfStream) throws Http2Exception

Checks if a new compressor object is needed for the stream identified by streamId. This method will modify the content-encoding header contained in headers.

Parameters
ctx:ChannelHandlerContext

the context.

headers:Http2Headers

Object representing headers which are to be written

endOfStream:boolean

Indicates if the stream has ended

Returns:EmbeddedChannel

The channel used to compress data.

Exceptions
Http2Exception:
if any problems occur during initialization.
newContentCompressorback to summary
protected EmbeddedChannel newContentCompressor(ChannelHandlerContext ctx, CharSequence contentEncoding) throws Http2Exception

Returns a new EmbeddedChannel that encodes the HTTP2 message content encoded in the specified contentEncoding.

Parameters
ctx:ChannelHandlerContext

the context.

contentEncoding:CharSequence

the value of the content-encoding header

Returns:EmbeddedChannel

a new ByteToMessageDecoder if the specified encoding is supported. null otherwise (alternatively, you can throw a Http2Exception to block unknown encoding).

Exceptions
Http2Exception:
If the specified encoding is not supported and warrants an exception
nextReadableBufback to summary
private static ByteBuf nextReadableBuf(EmbeddedChannel compressor)

Read the next compressed ByteBuf from the EmbeddedChannel or null if one does not exist.

Parameters
compressor:EmbeddedChannel

The channel to read from

Returns:ByteBuf

The next decoded ByteBuf from the EmbeddedChannel or null if one does not exist

writeDataback to summary
public ChannelFuture writeData(final ChannelHandlerContext ctx, final int streamId, ByteBuf data, int padding, final boolean endOfStream, ChannelPromise promise)

Overrides io.netty.handler.codec.http2.DecoratingHttp2FrameWriter.writeData.

Implements io.netty.handler.codec.http2.Http2DataWriter.writeData.

Doc from io.netty.handler.codec.http2.Http2DataWriter.writeData.

Writes a DATA frame to the remote endpoint. This will result in one or more frames being written to the context.

Parameters
ctx:ChannelHandlerContext

the context to use for writing.

streamId:int

the stream for which to send the frame.

data:ByteBuf

the payload of the frame. This will be released by this method.

padding:int

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:boolean

indicates if this is the last frame to be sent for the stream.

promise:ChannelPromise

the promise for the write.

Returns:ChannelFuture

the future for the write.

Annotations
@Override
writeHeadersback to summary
public ChannelFuture writeHeaders(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endStream, ChannelPromise promise)

Overrides io.netty.handler.codec.http2.DecoratingHttp2FrameWriter.writeHeaders.

Implements io.netty.handler.codec.http2.Http2FrameWriter.writeHeaders.

Doc from io.netty.handler.codec.http2.Http2FrameWriter.writeHeaders.

Writes a HEADERS frame to the remote endpoint.

Parameters
ctx:ChannelHandlerContext

the context to use for writing.

streamId:int

the stream for which to send the frame.

headers:Http2Headers

the headers to be sent.

padding:int

additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).

endStream:boolean

indicates if this is the last frame to be sent for the stream.

promise:ChannelPromise

the promise for the write.

Returns:ChannelFuture

the future for the write. Section 10.5.1 states the following:

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.

Annotations
@Override
writeHeadersback to summary
public ChannelFuture writeHeaders(final ChannelHandlerContext ctx, final int streamId, final Http2Headers headers, final int streamDependency, final short weight, final boolean exclusive, final int padding, final boolean endOfStream, final ChannelPromise promise)

Overrides io.netty.handler.codec.http2.DecoratingHttp2FrameWriter.writeHeaders.

Implements io.netty.handler.codec.http2.Http2FrameWriter.writeHeaders.

Doc from io.netty.handler.codec.http2.Http2FrameWriter.writeHeaders.

Writes a HEADERS frame with priority specified to the remote endpoint.

Parameters
ctx:ChannelHandlerContext

the context to use for writing.

streamId:int

the stream for which to send the frame.

headers:Http2Headers

the headers to be sent.

streamDependency:int

the stream on which this stream should depend, or 0 if it should depend on the connection.

weight:short

the weight for this stream.

exclusive:boolean

whether this stream should be the exclusive dependant of its parent.

padding:int

additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).

endOfStream:boolean

indicates if this is the last frame to be sent for the stream.

promise:ChannelPromise

the promise for the write.

Returns:ChannelFuture

the future for the write. Section 10.5.1 states the following:

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.

Annotations
@Override