Class StreamingInboundHttp2ToHttpAdapter

  • All Implemented Interfaces:
    io.netty.handler.codec.http2.Http2Connection.Listener, io.netty.handler.codec.http2.Http2FrameListener

    public class StreamingInboundHttp2ToHttpAdapter
    extends io.netty.handler.codec.http2.Http2EventAdapter
    Implementation of Http2EventAdapter that allows streaming requests for servers and responses for clients by establishing a processor that emits chunks as HttpContent. This implementation does not buffer the data. If you need data buffering a FlowControlHandler can be placed after this implementation so that downstream handlers can control flow. Based on code in InboundHttp2ToHttpAdapter.
    Since:
    2.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected io.netty.handler.codec.http2.Http2Connection connection  
      protected boolean validateHttpHeaders  
    • Constructor Summary

      Constructors 
      Constructor Description
      StreamingInboundHttp2ToHttpAdapter​(io.netty.handler.codec.http2.Http2Connection connection, int maxContentLength)
      Default constructor.
      StreamingInboundHttp2ToHttpAdapter​(io.netty.handler.codec.http2.Http2Connection connection, int maxContentLength, boolean validateHttpHeaders, boolean propagateSettings)
      Default constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void fireChannelRead​(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpContent msg, io.netty.handler.codec.http2.Http2Stream stream)
      fire a channel read event.
      protected void fireChannelRead​(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpMessage msg, io.netty.handler.codec.http2.Http2Stream stream)
      fire a channel read event.
      protected io.netty.handler.codec.http.HttpMessage getMessage​(io.netty.handler.codec.http2.Http2Stream stream)
      Get the FullHttpMessage associated with stream.
      protected io.netty.handler.codec.http.HttpMessage newMessage​(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http2.Http2Stream stream, io.netty.handler.codec.http2.Http2Headers headers, boolean validateHttpHeaders)
      Create a new FullHttpMessage based upon the current connection parameters.
      int onDataRead​(io.netty.channel.ChannelHandlerContext ctx, int streamId, io.netty.buffer.ByteBuf data, int padding, boolean endOfStream)  
      void onHeadersRead​(io.netty.channel.ChannelHandlerContext ctx, int streamId, io.netty.handler.codec.http2.Http2Headers headers, int padding, boolean endOfStream)  
      void onHeadersRead​(io.netty.channel.ChannelHandlerContext ctx, int streamId, io.netty.handler.codec.http2.Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endOfStream)  
      void onPushPromiseRead​(io.netty.channel.ChannelHandlerContext ctx, int streamId, int promisedStreamId, io.netty.handler.codec.http2.Http2Headers headers, int padding)  
      void onRstStreamRead​(io.netty.channel.ChannelHandlerContext ctx, int streamId, long errorCode)  
      protected void onRstStreamRead​(io.netty.handler.codec.http2.Http2Stream stream, io.netty.handler.codec.http.HttpMessage msg)
      Called if a RST_STREAM is received but we have some data for that stream.
      void onSettingsRead​(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http2.Http2Settings settings)  
      void onStreamRemoved​(io.netty.handler.codec.http2.Http2Stream stream)  
      protected io.netty.handler.codec.http.HttpMessage processHeadersBegin​(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http2.Http2Stream stream, io.netty.handler.codec.http2.Http2Headers headers, boolean allowAppend, boolean appendToTrailer)
      Provides translation between HTTP/2 and HTTP header objects while ensuring the stream is in a valid state for additional headers.
      protected void putMessage​(io.netty.handler.codec.http2.Http2Stream stream, io.netty.handler.codec.http.HttpMessage message)
      Make message be the state associated with stream.
      protected void removeMessage​(io.netty.handler.codec.http2.Http2Stream stream)
      The stream is out of scope for the HTTP message flow and will no longer be tracked.
      • Methods inherited from class io.netty.handler.codec.http2.Http2EventAdapter

        onGoAwayRead, onGoAwayReceived, onGoAwaySent, onPingAckRead, onPingRead, onPriorityRead, onSettingsAckRead, onStreamActive, onStreamAdded, onStreamClosed, onStreamHalfClosed, onUnknownFrame, onWindowUpdateRead
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • connection

        protected final io.netty.handler.codec.http2.Http2Connection connection
      • validateHttpHeaders

        protected final boolean validateHttpHeaders
    • Constructor Detail

      • StreamingInboundHttp2ToHttpAdapter

        public StreamingInboundHttp2ToHttpAdapter​(io.netty.handler.codec.http2.Http2Connection connection,
                                                  int maxContentLength,
                                                  boolean validateHttpHeaders,
                                                  boolean propagateSettings)
        Default constructor.
        Parameters:
        connection - The connection
        maxContentLength - The max content length
        validateHttpHeaders - Whether to validate headers
        propagateSettings - Whether to propagate settings
      • StreamingInboundHttp2ToHttpAdapter

        public StreamingInboundHttp2ToHttpAdapter​(io.netty.handler.codec.http2.Http2Connection connection,
                                                  int maxContentLength)
        Default constructor.
        Parameters:
        connection - The connection
        maxContentLength - The max content length
    • Method Detail

      • removeMessage

        protected final void removeMessage​(io.netty.handler.codec.http2.Http2Stream stream)
        The stream is out of scope for the HTTP message flow and will no longer be tracked.
        Parameters:
        stream - The stream to remove associated state with
      • getMessage

        protected final io.netty.handler.codec.http.HttpMessage getMessage​(io.netty.handler.codec.http2.Http2Stream stream)
        Get the FullHttpMessage associated with stream.
        Parameters:
        stream - The stream to get the associated state from
        Returns:
        The FullHttpMessage associated with stream.
      • putMessage

        protected final void putMessage​(io.netty.handler.codec.http2.Http2Stream stream,
                                        io.netty.handler.codec.http.HttpMessage message)
        Make message be the state associated with stream.
        Parameters:
        stream - The stream which message is associated with.
        message - The message which contains the HTTP semantics.
      • onStreamRemoved

        public void onStreamRemoved​(io.netty.handler.codec.http2.Http2Stream stream)
        Specified by:
        onStreamRemoved in interface io.netty.handler.codec.http2.Http2Connection.Listener
        Overrides:
        onStreamRemoved in class io.netty.handler.codec.http2.Http2EventAdapter
      • fireChannelRead

        protected void fireChannelRead​(io.netty.channel.ChannelHandlerContext ctx,
                                       io.netty.handler.codec.http.HttpContent msg,
                                       io.netty.handler.codec.http2.Http2Stream stream)
        fire a channel read event.
        Parameters:
        ctx - The context to fire the event on
        msg - The message to send
        stream - the stream of the message which is being fired
      • fireChannelRead

        protected void fireChannelRead​(io.netty.channel.ChannelHandlerContext ctx,
                                       io.netty.handler.codec.http.HttpMessage msg,
                                       io.netty.handler.codec.http2.Http2Stream stream)
        fire a channel read event.
        Parameters:
        ctx - The context to fire the event on
        msg - The message to send
        stream - the stream of the message which is being fired
      • newMessage

        protected io.netty.handler.codec.http.HttpMessage newMessage​(io.netty.channel.ChannelHandlerContext ctx,
                                                                     io.netty.handler.codec.http2.Http2Stream stream,
                                                                     io.netty.handler.codec.http2.Http2Headers headers,
                                                                     boolean validateHttpHeaders)
                                                              throws io.netty.handler.codec.http2.Http2Exception
        Create a new FullHttpMessage based upon the current connection parameters.
        Parameters:
        ctx - The channel context
        stream - The stream to create a message for
        headers - The headers associated with stream
        validateHttpHeaders -
        • true to validate HTTP headers in the http-codec
        • false not to validate HTTP headers in the http-codec
        Returns:
        A new StreamedHttpMessage
        Throws:
        io.netty.handler.codec.http2.Http2Exception - thrown if an error occurs creating the request
      • processHeadersBegin

        protected io.netty.handler.codec.http.HttpMessage processHeadersBegin​(io.netty.channel.ChannelHandlerContext ctx,
                                                                              io.netty.handler.codec.http2.Http2Stream stream,
                                                                              io.netty.handler.codec.http2.Http2Headers headers,
                                                                              boolean allowAppend,
                                                                              boolean appendToTrailer)
                                                                       throws io.netty.handler.codec.http2.Http2Exception
        Provides translation between HTTP/2 and HTTP header objects while ensuring the stream is in a valid state for additional headers.
        Parameters:
        ctx - The context for which this message has been received. Used to send informational header if detected.
        stream - The stream the headers apply to
        headers - The headers to process
        allowAppend -
        • true if headers will be appended if the stream already exists.
        • if false and the stream already exists this method returns null.
        appendToTrailer -
        • true if a message stream already exists then the headers should be added to the trailing headers.
        • false then appends will be done to the initial headers.
        Returns:
        The object used to track the stream corresponding to stream. null if allowAppend is false and the stream already exists.
        Throws:
        io.netty.handler.codec.http2.Http2Exception - If the stream id is not in the correct state to process the headers request
      • onDataRead

        public int onDataRead​(io.netty.channel.ChannelHandlerContext ctx,
                              int streamId,
                              io.netty.buffer.ByteBuf data,
                              int padding,
                              boolean endOfStream)
                       throws io.netty.handler.codec.http2.Http2Exception
        Specified by:
        onDataRead in interface io.netty.handler.codec.http2.Http2FrameListener
        Overrides:
        onDataRead in class io.netty.handler.codec.http2.Http2EventAdapter
        Throws:
        io.netty.handler.codec.http2.Http2Exception
      • onHeadersRead

        public void onHeadersRead​(io.netty.channel.ChannelHandlerContext ctx,
                                  int streamId,
                                  io.netty.handler.codec.http2.Http2Headers headers,
                                  int padding,
                                  boolean endOfStream)
                           throws io.netty.handler.codec.http2.Http2Exception
        Specified by:
        onHeadersRead in interface io.netty.handler.codec.http2.Http2FrameListener
        Overrides:
        onHeadersRead in class io.netty.handler.codec.http2.Http2EventAdapter
        Throws:
        io.netty.handler.codec.http2.Http2Exception
      • onHeadersRead

        public void onHeadersRead​(io.netty.channel.ChannelHandlerContext ctx,
                                  int streamId,
                                  io.netty.handler.codec.http2.Http2Headers headers,
                                  int streamDependency,
                                  short weight,
                                  boolean exclusive,
                                  int padding,
                                  boolean endOfStream)
                           throws io.netty.handler.codec.http2.Http2Exception
        Specified by:
        onHeadersRead in interface io.netty.handler.codec.http2.Http2FrameListener
        Overrides:
        onHeadersRead in class io.netty.handler.codec.http2.Http2EventAdapter
        Throws:
        io.netty.handler.codec.http2.Http2Exception
      • onRstStreamRead

        public void onRstStreamRead​(io.netty.channel.ChannelHandlerContext ctx,
                                    int streamId,
                                    long errorCode)
        Specified by:
        onRstStreamRead in interface io.netty.handler.codec.http2.Http2FrameListener
        Overrides:
        onRstStreamRead in class io.netty.handler.codec.http2.Http2EventAdapter
      • onPushPromiseRead

        public void onPushPromiseRead​(io.netty.channel.ChannelHandlerContext ctx,
                                      int streamId,
                                      int promisedStreamId,
                                      io.netty.handler.codec.http2.Http2Headers headers,
                                      int padding)
                               throws io.netty.handler.codec.http2.Http2Exception
        Specified by:
        onPushPromiseRead in interface io.netty.handler.codec.http2.Http2FrameListener
        Overrides:
        onPushPromiseRead in class io.netty.handler.codec.http2.Http2EventAdapter
        Throws:
        io.netty.handler.codec.http2.Http2Exception
      • onSettingsRead

        public void onSettingsRead​(io.netty.channel.ChannelHandlerContext ctx,
                                   io.netty.handler.codec.http2.Http2Settings settings)
                            throws io.netty.handler.codec.http2.Http2Exception
        Specified by:
        onSettingsRead in interface io.netty.handler.codec.http2.Http2FrameListener
        Overrides:
        onSettingsRead in class io.netty.handler.codec.http2.Http2EventAdapter
        Throws:
        io.netty.handler.codec.http2.Http2Exception
      • onRstStreamRead

        protected void onRstStreamRead​(io.netty.handler.codec.http2.Http2Stream stream,
                                       io.netty.handler.codec.http.HttpMessage msg)
        Called if a RST_STREAM is received but we have some data for that stream.
        Parameters:
        stream - The stream
        msg - The message