Package io.netty.handler.codec.http2
Class Http2StreamFrameToHttpObjectCodec
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.channel.ChannelDuplexHandler
-
- io.netty.handler.codec.MessageToMessageCodec<Http2StreamFrame,HttpObject>
-
- io.netty.handler.codec.http2.Http2StreamFrameToHttpObjectCodec
-
- All Implemented Interfaces:
ChannelHandler,ChannelInboundHandler,ChannelOutboundHandler
@UnstableApi @Sharable public class Http2StreamFrameToHttpObjectCodec extends MessageToMessageCodec<Http2StreamFrame,HttpObject>
This handler converts fromHttp2StreamFrametoHttpObject, and back. It can be used as an adapter in conjunction withHttp2MultiplexCodecto make http/2 connections backward-compatible withChannelHandlers expectingHttpObjectFor simplicity, it converts to chunked encoding unless the entire stream is a single header.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Field Summary
Fields Modifier and Type Field Description private booleanisServerprivate static AttributeKey<HttpScheme>SCHEME_ATTR_KEYprivate booleanvalidateHeaders
-
Constructor Summary
Constructors Constructor Description Http2StreamFrameToHttpObjectCodec(boolean isServer)Http2StreamFrameToHttpObjectCodec(boolean isServer, boolean validateHeaders)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanacceptInboundMessage(java.lang.Object msg)Returnstrueif and only if the specified message can be decoded by this codec.private static ChannelconnectionChannel(ChannelHandlerContext ctx)private static HttpSchemeconnectionScheme(ChannelHandlerContext ctx)private static Attribute<HttpScheme>connectionSchemeAttribute(ChannelHandlerContext ctx)protected voiddecode(ChannelHandlerContext ctx, Http2StreamFrame frame, java.util.List<java.lang.Object> out)protected voidencode(ChannelHandlerContext ctx, HttpObject obj, java.util.List<java.lang.Object> out)Encode from anHttpObjectto anHttp2StreamFrame.private voidencodeLastContent(LastHttpContent last, java.util.List<java.lang.Object> out)voidhandlerAdded(ChannelHandlerContext ctx)Do nothing by default, sub-classes may override this method.protected booleanisSsl(ChannelHandlerContext ctx)private FullHttpMessagenewFullMessage(int id, Http2Headers headers, ByteBufAllocator alloc)private HttpMessagenewMessage(int id, Http2Headers headers)private Http2HeaderstoHttp2Headers(ChannelHandlerContext ctx, HttpMessage msg)-
Methods inherited from class io.netty.handler.codec.MessageToMessageCodec
acceptOutboundMessage, channelRead, write
-
Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, read
-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerRemoved, isSharable
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty.channel.ChannelHandler
handlerRemoved
-
-
-
-
Field Detail
-
SCHEME_ATTR_KEY
private static final AttributeKey<HttpScheme> SCHEME_ATTR_KEY
-
isServer
private final boolean isServer
-
validateHeaders
private final boolean validateHeaders
-
-
Method Detail
-
acceptInboundMessage
public boolean acceptInboundMessage(java.lang.Object msg) throws java.lang.ExceptionDescription copied from class:MessageToMessageCodecReturnstrueif and only if the specified message can be decoded by this codec.- Overrides:
acceptInboundMessagein classMessageToMessageCodec<Http2StreamFrame,HttpObject>- Parameters:
msg- the message- Throws:
java.lang.Exception
-
decode
protected void decode(ChannelHandlerContext ctx, Http2StreamFrame frame, java.util.List<java.lang.Object> out) throws java.lang.Exception
- Specified by:
decodein classMessageToMessageCodec<Http2StreamFrame,HttpObject>- Throws:
java.lang.Exception- See Also:
MessageToMessageDecoder.decode(ChannelHandlerContext, Object, List)
-
encodeLastContent
private void encodeLastContent(LastHttpContent last, java.util.List<java.lang.Object> out)
-
encode
protected void encode(ChannelHandlerContext ctx, HttpObject obj, java.util.List<java.lang.Object> out) throws java.lang.Exception
Encode from anHttpObjectto anHttp2StreamFrame. This method will be called for each written message that can be handled by this encoder. NOTE: 100-Continue responses that are NOTFullHttpResponsewill be rejected.- Specified by:
encodein classMessageToMessageCodec<Http2StreamFrame,HttpObject>- Parameters:
ctx- theChannelHandlerContextwhich this handler belongs toobj- theHttpObjectmessage to encodeout- theListinto which the encoded msg should be added needs to do some kind of aggregation- Throws:
java.lang.Exception- is thrown if an error occurs- See Also:
MessageToMessageEncoder.encode(ChannelHandlerContext, Object, List)
-
toHttp2Headers
private Http2Headers toHttp2Headers(ChannelHandlerContext ctx, HttpMessage msg)
-
newMessage
private HttpMessage newMessage(int id, Http2Headers headers) throws Http2Exception
- Throws:
Http2Exception
-
newFullMessage
private FullHttpMessage newFullMessage(int id, Http2Headers headers, ByteBufAllocator alloc) throws Http2Exception
- Throws:
Http2Exception
-
handlerAdded
public void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerAddedin interfaceChannelHandler- Overrides:
handlerAddedin classChannelHandlerAdapter- Throws:
java.lang.Exception
-
isSsl
protected boolean isSsl(ChannelHandlerContext ctx)
-
connectionScheme
private static HttpScheme connectionScheme(ChannelHandlerContext ctx)
-
connectionSchemeAttribute
private static Attribute<HttpScheme> connectionSchemeAttribute(ChannelHandlerContext ctx)
-
connectionChannel
private static Channel connectionChannel(ChannelHandlerContext ctx)
-
-