Package io.netty.handler.codec.http2
Class DefaultHttp2FrameWriter
- java.lang.Object
-
- io.netty.handler.codec.http2.DefaultHttp2FrameWriter
-
- All Implemented Interfaces:
Http2DataWriter,Http2FrameSizePolicy,Http2FrameWriter,Http2FrameWriter.Configuration,java.io.Closeable,java.lang.AutoCloseable
public class DefaultHttp2FrameWriter extends java.lang.Object implements Http2FrameWriter, Http2FrameSizePolicy, Http2FrameWriter.Configuration
AHttp2FrameWriterthat supports all frame types defined by the HTTP/2 specification.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.netty.handler.codec.http2.Http2FrameWriter
Http2FrameWriter.Configuration
-
-
Constructor Summary
Constructors Constructor Description DefaultHttp2FrameWriter()DefaultHttp2FrameWriter(Http2HeadersEncoder headersEncoder)DefaultHttp2FrameWriter(Http2HeadersEncoder.SensitivityDetector headersSensitivityDetector)DefaultHttp2FrameWriter(Http2HeadersEncoder.SensitivityDetector headersSensitivityDetector, boolean ignoreMaxHeaderListSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this writer and frees any allocated resources.Http2FrameWriter.Configurationconfiguration()Get the configuration related elements for thisHttp2FrameWriterHttp2FrameSizePolicyframeSizePolicy()Get theHttp2FrameSizePolicyfor thisHttp2FrameWriterHttp2HeadersEncoder.ConfigurationheadersConfiguration()Get theHttp2HeadersEncoder.Configurationfor thisHttp2FrameWriterintmaxFrameSize()Gets the maximum allowed frame size.voidmaxFrameSize(int max)Sets the maximum allowed frame size.ChannelFuturewriteData(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endStream, ChannelPromise promise)Writes aDATAframe to the remote endpoint.ChannelFuturewriteFrame(ChannelHandlerContext ctx, byte frameType, int streamId, Http2Flags flags, ByteBuf payload, ChannelPromise promise)Generic write method for any HTTP/2 frame.ChannelFuturewriteGoAway(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData, ChannelPromise promise)Writes a GO_AWAY frame to the remote endpoint.ChannelFuturewriteHeaders(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endStream, ChannelPromise promise)Writes a HEADERS frame to the remote endpoint.ChannelFuturewriteHeaders(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream, ChannelPromise promise)Writes a HEADERS frame with priority specified to the remote endpoint.ChannelFuturewritePing(ChannelHandlerContext ctx, boolean ack, long data, ChannelPromise promise)Writes a PING frame to the remote endpoint.ChannelFuturewritePriority(ChannelHandlerContext ctx, int streamId, int streamDependency, short weight, boolean exclusive, ChannelPromise promise)Writes a PRIORITY frame to the remote endpoint.ChannelFuturewritePushPromise(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding, ChannelPromise promise)Writes a PUSH_PROMISE frame to the remote endpoint.ChannelFuturewriteRstStream(ChannelHandlerContext ctx, int streamId, long errorCode, ChannelPromise promise)Writes a RST_STREAM frame to the remote endpoint.ChannelFuturewriteSettings(ChannelHandlerContext ctx, Http2Settings settings, ChannelPromise promise)Writes a SETTINGS frame to the remote endpoint.ChannelFuturewriteSettingsAck(ChannelHandlerContext ctx, ChannelPromise promise)Writes a SETTINGS acknowledgment to the remote endpoint.ChannelFuturewriteWindowUpdate(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement, ChannelPromise promise)Writes a WINDOW_UPDATE frame to the remote endpoint.
-
-
-
Constructor Detail
-
DefaultHttp2FrameWriter
public DefaultHttp2FrameWriter()
-
DefaultHttp2FrameWriter
public DefaultHttp2FrameWriter(Http2HeadersEncoder.SensitivityDetector headersSensitivityDetector)
-
DefaultHttp2FrameWriter
public DefaultHttp2FrameWriter(Http2HeadersEncoder.SensitivityDetector headersSensitivityDetector, boolean ignoreMaxHeaderListSize)
-
DefaultHttp2FrameWriter
public DefaultHttp2FrameWriter(Http2HeadersEncoder headersEncoder)
- Parameters:
headersEncoder- will be closed if it implementsCloseable
-
-
Method Detail
-
configuration
public Http2FrameWriter.Configuration configuration()
Description copied from interface:Http2FrameWriterGet the configuration related elements for thisHttp2FrameWriter- Specified by:
configurationin interfaceHttp2FrameWriter
-
headersConfiguration
public Http2HeadersEncoder.Configuration headersConfiguration()
Description copied from interface:Http2FrameWriter.ConfigurationGet theHttp2HeadersEncoder.Configurationfor thisHttp2FrameWriter- Specified by:
headersConfigurationin interfaceHttp2FrameWriter.Configuration
-
frameSizePolicy
public Http2FrameSizePolicy frameSizePolicy()
Description copied from interface:Http2FrameWriter.ConfigurationGet theHttp2FrameSizePolicyfor thisHttp2FrameWriter- Specified by:
frameSizePolicyin interfaceHttp2FrameWriter.Configuration
-
maxFrameSize
public void maxFrameSize(int max) throws Http2ExceptionDescription copied from interface:Http2FrameSizePolicySets the maximum allowed frame size. Attempts to write frames longer than this maximum will fail.This value is used to represent SETTINGS_MAX_FRAME_SIZE. This method should only be called by Netty (not users) as a result of a receiving a
SETTINGSframe.- Specified by:
maxFrameSizein interfaceHttp2FrameSizePolicy- Throws:
Http2Exception
-
maxFrameSize
public int maxFrameSize()
Description copied from interface:Http2FrameSizePolicyGets the maximum allowed frame size.This value is used to represent SETTINGS_MAX_FRAME_SIZE. The initial value defined by the RFC is unlimited but enforcing a lower limit is generally permitted.
Http2CodecUtil.DEFAULT_MAX_FRAME_SIZEcan be used as a more conservative default.- Specified by:
maxFrameSizein interfaceHttp2FrameSizePolicy
-
close
public void close()
Description copied from interface:Http2FrameWriterCloses this writer and frees any allocated resources.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceHttp2FrameWriter
-
writeData
public ChannelFuture writeData(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endStream, ChannelPromise promise)
Description copied from interface:Http2DataWriterWrites aDATAframe to the remote endpoint. This will result in one or more frames being written to the context.- Specified by:
writeDatain interfaceHttp2DataWriter- 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.endStream- indicates if this is the last frame to be sent for the stream.promise- the promise for the write.- Returns:
- the future for the write.
-
writeHeaders
public ChannelFuture writeHeaders(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endStream, ChannelPromise promise)
Description copied from interface:Http2FrameWriterWrites a HEADERS frame to the remote endpoint.- Specified by:
writeHeadersin interfaceHttp2FrameWriter- 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.promise- the promise for the write.- 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 ChannelFuture writeHeaders(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream, ChannelPromise promise)
Description copied from interface:Http2FrameWriterWrites a HEADERS frame with priority specified to the remote endpoint.- Specified by:
writeHeadersin interfaceHttp2FrameWriter- 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).endStream- indicates if this is the last frame to be sent for the stream.promise- the promise for the write.- 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.
-
writePriority
public ChannelFuture writePriority(ChannelHandlerContext ctx, int streamId, int streamDependency, short weight, boolean exclusive, ChannelPromise promise)
Description copied from interface:Http2FrameWriterWrites a PRIORITY frame to the remote endpoint.- Specified by:
writePriorityin interfaceHttp2FrameWriter- Parameters:
ctx- the context to use for writing.streamId- the stream for which to send the frame.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.promise- the promise for the write.- Returns:
- the future for the write.
-
writeRstStream
public ChannelFuture writeRstStream(ChannelHandlerContext ctx, int streamId, long errorCode, ChannelPromise promise)
Description copied from interface:Http2FrameWriterWrites a RST_STREAM frame to the remote endpoint.- Specified by:
writeRstStreamin interfaceHttp2FrameWriter- Parameters:
ctx- the context to use for writing.streamId- the stream for which to send the frame.errorCode- the error code indicating the nature of the failure.promise- the promise for the write.- Returns:
- the future for the write.
-
writeSettings
public ChannelFuture writeSettings(ChannelHandlerContext ctx, Http2Settings settings, ChannelPromise promise)
Description copied from interface:Http2FrameWriterWrites a SETTINGS frame to the remote endpoint.- Specified by:
writeSettingsin interfaceHttp2FrameWriter- Parameters:
ctx- the context to use for writing.settings- the settings to be sent.promise- the promise for the write.- Returns:
- the future for the write.
-
writeSettingsAck
public ChannelFuture writeSettingsAck(ChannelHandlerContext ctx, ChannelPromise promise)
Description copied from interface:Http2FrameWriterWrites a SETTINGS acknowledgment to the remote endpoint.- Specified by:
writeSettingsAckin interfaceHttp2FrameWriter- Parameters:
ctx- the context to use for writing.promise- the promise for the write.- Returns:
- the future for the write.
-
writePing
public ChannelFuture writePing(ChannelHandlerContext ctx, boolean ack, long data, ChannelPromise promise)
Description copied from interface:Http2FrameWriterWrites a PING frame to the remote endpoint.- Specified by:
writePingin interfaceHttp2FrameWriter- Parameters:
ctx- the context to use for writing.ack- indicates whether this is an ack of a PING frame previously received from the remote endpoint.data- the payload of the frame.promise- the promise for the write.- Returns:
- the future for the write.
-
writePushPromise
public ChannelFuture writePushPromise(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding, ChannelPromise promise)
Description copied from interface:Http2FrameWriterWrites a PUSH_PROMISE frame to the remote endpoint.- Specified by:
writePushPromisein interfaceHttp2FrameWriter- Parameters:
ctx- the context to use for writing.streamId- the stream for which to send the frame.promisedStreamId- the ID of the promised stream.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).promise- the promise for the write.- 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.
-
writeGoAway
public ChannelFuture writeGoAway(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData, ChannelPromise promise)
Description copied from interface:Http2FrameWriterWrites a GO_AWAY frame to the remote endpoint.- Specified by:
writeGoAwayin interfaceHttp2FrameWriter- Parameters:
ctx- the context to use for writing.lastStreamId- the last known stream of this endpoint.errorCode- the error code, if the connection was abnormally terminated.debugData- application-defined debug data. This will be released by this method.promise- the promise for the write.- Returns:
- the future for the write.
-
writeWindowUpdate
public ChannelFuture writeWindowUpdate(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement, ChannelPromise promise)
Description copied from interface:Http2FrameWriterWrites a WINDOW_UPDATE frame to the remote endpoint.- Specified by:
writeWindowUpdatein interfaceHttp2FrameWriter- Parameters:
ctx- the context to use for writing.streamId- the stream for which to send the frame.windowSizeIncrement- the number of bytes by which the local inbound flow control window is increasing.promise- the promise for the write.- Returns:
- the future for the write.
-
writeFrame
public ChannelFuture writeFrame(ChannelHandlerContext ctx, byte frameType, int streamId, Http2Flags flags, ByteBuf payload, ChannelPromise promise)
Description copied from interface:Http2FrameWriterGeneric write method for any HTTP/2 frame. This allows writing of non-standard frames.- Specified by:
writeFramein interfaceHttp2FrameWriter- Parameters:
ctx- the context to use for writing.frameType- the frame type identifier.streamId- the stream for which to send the frame.flags- the flags to write for this frame.payload- the payload to write for this frame. This will be released by this method.promise- the promise for the write.- Returns:
- the future for the write.
-
-