@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)) | +-----------------------------------------------------------------------------------------------> | | + +
ChannelHandler.Sharable| Constructor and Description |
|---|
Http2FrameCodec(boolean server)
Construct a new handler.
|
Http2FrameCodec(boolean server,
Http2FrameLogger frameLogger)
Construct a new handler.
|
| Modifier and Type | Method and Description |
|---|---|
void |
exceptionCaught(ChannelHandlerContext ctx,
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,
Object evt)
Handles the cleartext HTTP upgrade event.
|
void |
write(ChannelHandlerContext ctx,
Object msg,
ChannelPromise promise)
Processes all
Http2Frames. |
bind, close, connect, deregister, disconnect, flush, readchannelActive, channelInactive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChangedensureNotSharable, isSharablepublic Http2FrameCodec(boolean server)
server - true this is a serverpublic Http2FrameCodec(boolean server,
Http2FrameLogger frameLogger)
server - true this is a serverpublic void handlerAdded(ChannelHandlerContext ctx) throws Exception
handlerAdded in interface ChannelHandlerhandlerAdded in class ChannelHandlerAdapterExceptionpublic void handlerRemoved(ChannelHandlerContext ctx) throws Exception
handlerRemoved in interface ChannelHandlerhandlerRemoved in class ChannelHandlerAdapterExceptionpublic void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception
userEventTriggered in interface ChannelInboundHandleruserEventTriggered in class ChannelInboundHandlerAdapterExceptionpublic void exceptionCaught(ChannelHandlerContext ctx, 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, 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 completesCopyright © 2008–2017 The Netty Project. All rights reserved.