@UnstableApi
public class Http2FrameCodec
extends io.netty.channel.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.
Http2FrameCodec
Http2MultiplexCodec
+ + | 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
.
Http2FrameCodec
Http2MultiplexCodec
+ + | 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
.
Http2FrameCodec
Http2MultiplexCodec
+ + | 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.
Http2FrameCodec
Http2MultiplexCodec
+ + | Http2HeadersFrame(streamId=-1) | <-----------------------------------------------------------------------------------------------+ | | | Http2StreamActiveEvent(streamId=2, headers=Http2HeadersFrame(streamId=-1)) | +-----------------------------------------------------------------------------------------------> | | + +
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(io.netty.channel.ChannelHandlerContext ctx,
Throwable cause) |
void |
handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
Load any dependencies.
|
void |
handlerRemoved(io.netty.channel.ChannelHandlerContext ctx)
Clean up any dependencies.
|
void |
userEventTriggered(io.netty.channel.ChannelHandlerContext ctx,
Object evt)
Handles the cleartext HTTP upgrade event.
|
void |
write(io.netty.channel.ChannelHandlerContext ctx,
Object msg,
io.netty.channel.ChannelPromise promise)
Processes all
Http2Frame s. |
bind, close, connect, deregister, disconnect, flush, read
public Http2FrameCodec(boolean server)
server
- true
this is a serverpublic Http2FrameCodec(boolean server, Http2FrameLogger frameLogger)
server
- true
this is a serverpublic void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws Exception
handlerAdded
in interface io.netty.channel.ChannelHandler
handlerAdded
in class io.netty.channel.ChannelHandlerAdapter
Exception
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws Exception
handlerRemoved
in interface io.netty.channel.ChannelHandler
handlerRemoved
in class io.netty.channel.ChannelHandlerAdapter
Exception
public void userEventTriggered(io.netty.channel.ChannelHandlerContext ctx, Object evt) throws Exception
userEventTriggered
in interface io.netty.channel.ChannelInboundHandler
userEventTriggered
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
exceptionCaught
in interface io.netty.channel.ChannelHandler
exceptionCaught
in interface io.netty.channel.ChannelInboundHandler
exceptionCaught
in class io.netty.channel.ChannelInboundHandlerAdapter
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)
Http2Frame
s. Http2StreamFrame
s may only originate in child
streams.write
in interface io.netty.channel.ChannelOutboundHandler
write
in class io.netty.channel.ChannelDuplexHandler
Copyright © 2008–2017 The Netty Project. All rights reserved.