@UnstableApi public class Http2FrameCodec extends ChannelDuplexHandler
Http2Frame objects and vice versa. For every incoming HTTP/2
frame a Http2Frame object is created and propagated via ChannelInboundHandlerAdapter.channelRead(io.netty.channel.ChannelHandlerContext, java.lang.Object). Outbound Http2Frame
objects received via write(io.netty.channel.ChannelHandlerContext, java.lang.Object, io.netty.channel.ChannelPromise) are converted to the HTTP/2 wire format.
A change in stream state is propagated through the channel pipeline as a user event via
Http2StreamStateEvent objects. When a HTTP/2 stream first becomes active a Http2StreamActiveEvent
and when it gets closed a Http2StreamClosedEvent is emitted.
Server-side HTTP to HTTP/2 upgrade is supported in conjunction with Http2ServerUpgradeCodec; the necessary
HTTP-to-HTTP/2 conversion is performed automatically.
This API is very immature. The Http2Connection-based API is currently preferred over this API. This API is targeted to eventually replace or reduce the need for the Http2Connection-based API.
When the remote side opens a new stream, the frame codec first emits a Http2StreamActiveEvent with the
stream identifier set.
Http2FrameCodecHttp2MultiplexCodec+ + | Http2StreamActiveEvent(streamId=3, headers=null) | +-------------------------------------------------------------> | | | Http2HeadersFrame(streamId=3) | +-------------------------------------------------------------> | | + +
When a stream is closed either due to a reset frame by the remote side, or due to both sides having sent frames
with the END_STREAM flag, then the frame codec emits a Http2StreamClosedEvent.
Http2FrameCodecHttp2MultiplexCodec+ + | Http2StreamClosedEvent(streamId=3) | +---------------------------------------------------------> | | + +
When the local side wants to close a stream, it has to write a Http2ResetFrame to which the frame codec
will respond to with a Http2StreamClosedEvent.
Http2FrameCodecHttp2MultiplexCodec+ + | Http2ResetFrame(streamId=3) | <---------------------------------------------------------+ | | | Http2StreamClosedEvent(streamId=3) | +---------------------------------------------------------> | | + +
Opening an outbound/local stream works by first sending the frame codec a Http2HeadersFrame with no
stream identifier set (such that Http2CodecUtil.isStreamIdValid(int) returns false). If opening the stream
was successful, the frame codec responds with a Http2StreamActiveEvent that contains the stream's new
identifier as well as the same Http2HeadersFrame object that opened the stream.
Http2FrameCodecHttp2MultiplexCodec+ + | Http2HeadersFrame(streamId=-1) | <-----------------------------------------------------------------------------------------------+ | | | Http2StreamActiveEvent(streamId=2, headers=Http2HeadersFrame(streamId=-1)) | +-----------------------------------------------------------------------------------------------> | | + +
| Modifier and Type | Class and Description |
|---|---|
private class |
Http2FrameCodec.ConnectionListener |
private static class |
Http2FrameCodec.FrameListener |
private static class |
Http2FrameCodec.InternalHttp2ConnectionHandler |
ChannelHandler.Sharable| Modifier and Type | Field and Description |
|---|---|
private ChannelHandlerContext |
ctx |
private static Http2FrameLogger |
HTTP2_FRAME_LOGGER |
private Http2ConnectionHandler |
http2Handler |
private ChannelHandlerContext |
http2HandlerCtx |
private boolean |
server |
| Constructor and Description |
|---|
Http2FrameCodec(boolean server)
Construct a new handler.
|
Http2FrameCodec(boolean server,
Http2FrameLogger frameLogger)
Construct a new handler.
|
Http2FrameCodec(boolean server,
Http2FrameWriter frameWriter,
Http2FrameLogger frameLogger,
Http2Settings initialSettings) |
| Modifier and Type | Method and Description |
|---|---|
(package private) Http2ConnectionHandler |
connectionHandler() |
private void |
consumeBytes(int streamId,
int bytes,
ChannelPromise promise) |
void |
exceptionCaught(ChannelHandlerContext ctx,
java.lang.Throwable cause)
Calls
ChannelHandlerContext.fireExceptionCaught(Throwable) to forward
to the next ChannelHandler in the ChannelPipeline. |
void |
handlerAdded(ChannelHandlerContext ctx)
Load any dependencies.
|
void |
handlerRemoved(ChannelHandlerContext ctx)
Clean up any dependencies.
|
void |
userEventTriggered(ChannelHandlerContext ctx,
java.lang.Object evt)
Handles the cleartext HTTP upgrade event.
|
void |
write(ChannelHandlerContext ctx,
java.lang.Object msg,
ChannelPromise promise)
Processes all
Http2Frames. |
private void |
writeGoAwayFrame(Http2GoAwayFrame frame,
ChannelPromise promise) |
private void |
writeHeadersFrame(Http2HeadersFrame headersFrame,
ChannelPromise promise) |
private void |
writeStreamFrame(Http2StreamFrame frame,
ChannelPromise promise) |
bind, close, connect, deregister, disconnect, flush, readchannelActive, channelInactive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChangedensureNotSharable, isSharableprivate static final Http2FrameLogger HTTP2_FRAME_LOGGER
private final Http2ConnectionHandler http2Handler
private final boolean server
private ChannelHandlerContext ctx
private ChannelHandlerContext http2HandlerCtx
public Http2FrameCodec(boolean server)
server - true this is a serverpublic Http2FrameCodec(boolean server,
Http2FrameLogger frameLogger)
server - true this is a serverHttp2FrameCodec(boolean server,
Http2FrameWriter frameWriter,
Http2FrameLogger frameLogger,
Http2Settings initialSettings)
Http2ConnectionHandler connectionHandler()
public void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
handlerAdded in interface ChannelHandlerhandlerAdded in class ChannelHandlerAdapterjava.lang.Exceptionpublic void handlerRemoved(ChannelHandlerContext ctx) throws java.lang.Exception
handlerRemoved in interface ChannelHandlerhandlerRemoved in class ChannelHandlerAdapterjava.lang.Exceptionpublic void userEventTriggered(ChannelHandlerContext ctx, java.lang.Object evt) throws java.lang.Exception
userEventTriggered in interface ChannelInboundHandleruserEventTriggered in class ChannelInboundHandlerAdapterjava.lang.Exceptionpublic void exceptionCaught(ChannelHandlerContext ctx, java.lang.Throwable cause)
ChannelInboundHandlerAdapterChannelHandlerContext.fireExceptionCaught(Throwable) to forward
to the next ChannelHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.exceptionCaught in interface ChannelHandlerexceptionCaught in interface ChannelInboundHandlerexceptionCaught in class ChannelInboundHandlerAdapterpublic void write(ChannelHandlerContext ctx, java.lang.Object msg, ChannelPromise promise)
Http2Frames. Http2StreamFrames may only originate in child
streams.write in interface ChannelOutboundHandlerwrite in class ChannelDuplexHandlerctx - the ChannelHandlerContext for which the write operation is mademsg - the message to writepromise - the ChannelPromise to notify once the operation completesprivate void consumeBytes(int streamId,
int bytes,
ChannelPromise promise)
private void writeGoAwayFrame(Http2GoAwayFrame frame, ChannelPromise promise)
private void writeStreamFrame(Http2StreamFrame frame, ChannelPromise promise)
private void writeHeadersFrame(Http2HeadersFrame headersFrame, ChannelPromise promise)