Class LoopbackHttp2StreamIdRemapper

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
org.mockserver.netty.proxy.relay.LoopbackHttp2StreamIdRemapper
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, io.netty.channel.ChannelOutboundHandler

public class LoopbackHttp2StreamIdRemapper extends io.netty.channel.ChannelDuplexHandler
Gives each request the CONNECT/SOCKS relay writes to its HTTP/2 loopback a loopback stream id of its own, and puts the proxy client's stream id back on the response. Requests reach the loopback in the order they finish, not the order their streams opened, and a client stream id is only ever increasing on the client's connection: reused on the loopback (x-http2-stream-id), a stream that finished after a later one would be opened below the last loopback id, which is a connection error that closes the whole tunnel.

Each pair is forgotten when its loopback stream is removed, so a long-lived tunnel holds one entry per open stream. A loopback response with no pair (only a server push could have one) is dropped, as is one whose client stream has ended. A response relayed as it is streamed arrives in parts (StreamedHttp2ResponsePart), each mapped alike. Flow control and PRIORITY frames are not relayed between the legs, and a GOAWAY is not translated: LoopbackHttp2ConnectionCloseHandler sends the client one of its own, from the client connection's ids. A priority dependency on a request is translated, or dropped when it names no open stream. Sits after the loopback's Http2ConnectionHandler; one per loopback. It reads and marks the proxy client connection's streams directly, which is safe only because the loopback is bootstrapped on the proxy client's event loop (RelayConnectHandler.channelRead0), so both channels, both connections and this handler are confined to that one thread.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

    io.netty.channel.ChannelHandler.Sharable
  • Constructor Summary

    Constructors
    Constructor
    Description
    LoopbackHttp2StreamIdRemapper(org.mockserver.logging.MockServerLogger mockServerLogger, io.netty.handler.codec.http2.Http2Connection loopbackConnection, io.netty.channel.Channel proxyClientChannel)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)
     
    void
    write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)
     

    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, handlerAdded, 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

    handlerAdded, handlerRemoved
  • Constructor Details

    • LoopbackHttp2StreamIdRemapper

      public LoopbackHttp2StreamIdRemapper(org.mockserver.logging.MockServerLogger mockServerLogger, io.netty.handler.codec.http2.Http2Connection loopbackConnection, io.netty.channel.Channel proxyClientChannel)
  • Method Details

    • write

      public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)
      Specified by:
      write in interface io.netty.channel.ChannelOutboundHandler
      Overrides:
      write in class io.netty.channel.ChannelDuplexHandler
    • channelRead

      public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)
      Specified by:
      channelRead in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelRead in class io.netty.channel.ChannelInboundHandlerAdapter