Module io.netty.codec.http2
Package io.netty5.handler.codec.http2
Class CompressorHttp2ConnectionEncoder
- java.lang.Object
-
- io.netty5.handler.codec.http2.DecoratingHttp2FrameWriter
-
- io.netty5.handler.codec.http2.DecoratingHttp2ConnectionEncoder
-
- io.netty5.handler.codec.http2.CompressorHttp2ConnectionEncoder
-
- All Implemented Interfaces:
Http2ConnectionEncoder
,Http2DataWriter
,Http2FrameWriter
,Http2SettingsReceivedConsumer
,Closeable
,AutoCloseable
@UnstableApi public class CompressorHttp2ConnectionEncoder extends DecoratingHttp2ConnectionEncoder
A decorating HTTP2 encoder that will compress data frames according to thecontent-encoding
header for each stream. The compression provided by this class will be applied to the data for the entire stream.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.netty5.handler.codec.http2.Http2FrameWriter
Http2FrameWriter.Configuration
-
-
Constructor Summary
Constructors Constructor Description CompressorHttp2ConnectionEncoder(Http2ConnectionEncoder delegate)
Create a newCompressorHttp2ConnectionEncoder
instance with default implementation ofStandardCompressionOptions
CompressorHttp2ConnectionEncoder(Http2ConnectionEncoder delegate, int compressionLevel, int windowBits, int memLevel)
Deprecated.CompressorHttp2ConnectionEncoder(Http2ConnectionEncoder delegate, CompressionOptions... compressionOptionsArgs)
Create a newCompressorHttp2ConnectionEncoder
with specifiedStandardCompressionOptions
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected CharSequence
getTargetContentEncoding(CharSequence contentEncoding)
Returns the expected content encoding of the decoded content.protected Compressor
newContentCompressor(ChannelHandlerContext ctx, CharSequence contentEncoding)
Returns a newCompressor
that encodes the HTTP2 message content encoded in the specifiedcontentEncoding
.Future<Void>
writeData(ChannelHandlerContext ctx, int streamId, Buffer data, int padding, boolean endOfStream)
Writes aDATA
frame to the remote endpoint.Future<Void>
writeHeaders(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endStream)
Writes a HEADERS frame to the remote endpoint.Future<Void>
writeHeaders(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endOfStream)
Writes a HEADERS frame with priority specified to the remote endpoint.-
Methods inherited from class io.netty5.handler.codec.http2.DecoratingHttp2ConnectionEncoder
connection, consumeReceivedSettings, flowController, frameWriter, lifecycleManager, pollSentSettings, remoteSettings
-
Methods inherited from class io.netty5.handler.codec.http2.DecoratingHttp2FrameWriter
close, configuration, writeFrame, writeGoAway, writePing, writePriority, writePushPromise, writeRstStream, writeSettings, writeSettingsAck, writeWindowUpdate
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.handler.codec.http2.Http2ConnectionEncoder
writeFrame
-
Methods inherited from interface io.netty5.handler.codec.http2.Http2FrameWriter
close, configuration, writeGoAway, writePing, writePriority, writePushPromise, writeRstStream, writeSettings, writeSettingsAck, writeWindowUpdate
-
-
-
-
Constructor Detail
-
CompressorHttp2ConnectionEncoder
public CompressorHttp2ConnectionEncoder(Http2ConnectionEncoder delegate)
Create a newCompressorHttp2ConnectionEncoder
instance with default implementation ofStandardCompressionOptions
-
CompressorHttp2ConnectionEncoder
@Deprecated public CompressorHttp2ConnectionEncoder(Http2ConnectionEncoder delegate, int compressionLevel, int windowBits, int memLevel)
Deprecated.Create a newCompressorHttp2ConnectionEncoder
instance
-
CompressorHttp2ConnectionEncoder
public CompressorHttp2ConnectionEncoder(Http2ConnectionEncoder delegate, CompressionOptions... compressionOptionsArgs)
Create a newCompressorHttp2ConnectionEncoder
with specifiedStandardCompressionOptions
-
-
Method Detail
-
writeData
public Future<Void> writeData(ChannelHandlerContext ctx, int streamId, Buffer data, int padding, boolean endOfStream)
Description copied from interface:Http2DataWriter
Writes aDATA
frame to the remote endpoint. This will result in one or more frames being written to the context.- Specified by:
writeData
in interfaceHttp2DataWriter
- Overrides:
writeData
in classDecoratingHttp2FrameWriter
- Parameters:
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.- Returns:
- the future for the write.
-
writeHeaders
public Future<Void> writeHeaders(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endStream)
Description copied from interface:Http2FrameWriter
Writes a HEADERS frame to the remote endpoint.- Specified by:
writeHeaders
in interfaceHttp2FrameWriter
- Overrides:
writeHeaders
in classDecoratingHttp2FrameWriter
- Parameters:
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.- Returns:
- 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.
-
writeHeaders
public Future<Void> writeHeaders(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endOfStream)
Description copied from interface:Http2FrameWriter
Writes a HEADERS frame with priority specified to the remote endpoint.- Specified by:
writeHeaders
in interfaceHttp2FrameWriter
- Overrides:
writeHeaders
in classDecoratingHttp2FrameWriter
- Parameters:
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.- Returns:
- 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.
-
newContentCompressor
protected Compressor newContentCompressor(ChannelHandlerContext ctx, CharSequence contentEncoding) throws Http2Exception
Returns a newCompressor
that encodes the HTTP2 message content encoded in the specifiedcontentEncoding
.- Parameters:
ctx
- the context.contentEncoding
- the value of thecontent-encoding
header- Returns:
- a new
ByteToMessageDecoder
if the specified encoding is supported. Otherwisenull
. Alternatively, you can throw aHttp2Exception
to block unknown encoding. - Throws:
Http2Exception
- If the specified encoding is not supported and warrants an exception
-
getTargetContentEncoding
protected CharSequence getTargetContentEncoding(CharSequence contentEncoding) throws Http2Exception
Returns the expected content encoding of the decoded content. ReturningcontentEncoding
is the default behavior, which is the case for most compressors.- Parameters:
contentEncoding
- the value of thecontent-encoding
header- Returns:
- the expected content encoding of the new content.
- Throws:
Http2Exception
- if thecontentEncoding
is not supported and warrants an exception
-
-