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

public Class CompressorHttp2ConnectionEncoder

extends DecoratingHttp2ConnectionEncoder
Class Inheritance
Annotations
@UnstableApi
Imports
io.netty5.buffer.Buffer, io.netty5.channel.ChannelHandlerContext, io.netty5.channel.embedded.EmbeddedChannel, io.netty5.handler.codec.ByteToMessageDecoder, io.netty5.handler.codec.compression.Brotli, .BrotliCompressor, .BrotliOptions, .CompressionOptions, .Compressor, .DeflateOptions, .GzipOptions, .StandardCompressionOptions, .ZlibCompressor, .ZlibWrapper, .ZstdCompressor, .ZstdOptions, io.netty5.handler.codec.http2.headers.Http2Headers, io.netty5.util.concurrent.Future, .Promise, .PromiseCombiner, io.netty5.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 DeflateOptions
private GzipOptions
private final Http2Connection.PropertyKey
private final boolean
private ZstdOptions

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
private void
bindCompressorToStream(Compressor
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
,
Compressor
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 Compressor
newCompressionChannel(final ChannelHandlerContext
the context.
ctx
,
ZlibWrapper
Defines what type of encoder should be used
wrapper
)

Generate a new instance of an Compressor capable of compressing data

private Compressor

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 Compressor

Returns:

a new ByteToMessageDecoder if the specified encoding is supported. Otherwise null. 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 Compressor that encodes the HTTP2 message content encoded in the specified contentEncoding.

public Future<Void>
writeData(final ChannelHandlerContext
the context to use for writing.
ctx
,
final int
the stream for which to send the frame.
streamId
,
Buffer
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
)

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

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

Writes a DATA frame to the remote endpoint.
public Future<Void>
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
)

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

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

Writes a HEADERS frame to the remote endpoint.
public Future<Void>
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
)

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

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

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

Field Detail

brotliOptionsback to summary
private BrotliOptions brotliOptions
deflateOptionsback to summary
private DeflateOptions deflateOptions
gzipCompressionOptionsback to summary
private GzipOptions gzipCompressionOptions
propertyKeyback to summary
private final Http2Connection.PropertyKey propertyKey
supportsCompressionOptionsback to summary
private final boolean supportsCompressionOptions
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, CompressionOptions... compressionOptionsArgs)

Create a new CompressorHttp2ConnectionEncoder with specified StandardCompressionOptions

Method Detail

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

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

Parameters
compressor:Compressor

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, Compressor 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:Compressor

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 Compressor newCompressionChannel(final ChannelHandlerContext ctx, ZlibWrapper wrapper)

Generate a new instance of an Compressor capable of compressing data

Parameters
ctx:ChannelHandlerContext

the context.

wrapper:ZlibWrapper

Defines what type of encoder should be used

newCompressorback to summary
private Compressor 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:Compressor

The channel used to compress data.

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

Returns a new Compressor 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:Compressor

a new ByteToMessageDecoder if the specified encoding is supported. Otherwise null. Alternatively, you can throw a Http2Exception to block unknown encoding.

Exceptions
Http2Exception:
If the specified encoding is not supported and warrants an exception
writeDataback to summary
public Future<Void> writeData(final ChannelHandlerContext ctx, final int streamId, Buffer data, int padding, final boolean endOfStream)

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

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

Doc from io.netty5.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:Buffer

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.

Returns:Future<Void>

the future for the write.

Annotations
@Override
writeHeadersback to summary
public Future<Void> writeHeaders(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endStream)

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

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

Doc from io.netty5.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.

Returns:Future<Void>

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 Future<Void> 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)

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

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

Doc from io.netty5.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.

Returns:Future<Void>

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