Class Http2MultiplexChildInitializer

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelInitializer<io.netty.handler.codec.http2.Http2StreamChannel>
org.mockserver.netty.unification.Http2MultiplexChildInitializer
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler

public class Http2MultiplexChildInitializer extends io.netty.channel.ChannelInitializer<io.netty.handler.codec.http2.Http2StreamChannel>
Per-stream child initializer used with Http2MultiplexHandler to build the pipeline for every HTTP/2 stream. Since issue #2669 the multiplex pipeline is the only HTTP/2 server pipeline (h2 and h2c alike), so this initializer runs for all HTTP/2 traffic — ordinary HTTP GET/POST/SSE, the dashboard, MCP, proxying, and gRPC — not just when gRPC bidi streaming is enabled.

Per-stream routing. initChannel(io.netty.handler.codec.http2.Http2StreamChannel) installs GrpcBidiRouterHandler as the first handler only when grpcBidiStreamingEnabled() is on AND the gRPC descriptor store has services — the only configuration under which a stream can be a true gRPC bidi method that needs a dedicated streaming handler. In that case the router inspects the first HEADERS frame and either installs the bidi streaming handler (for a matched bidi method) or the re-aggregating chain (for everything else). When bidi routing is not possible the router would always fall through to the re-aggregating chain, so this initializer skips it entirely and installs the re-aggregating chain directly — a pointless per-stream handler avoided on the common path.

The re-aggregating chain (Http2StreamFrameToHttpObjectCodec + HttpObjectAggregator + downstream handlers) is factored into the static installReAggregatingChain(io.netty.channel.ChannelPipeline, org.mockserver.configuration.Configuration, org.mockserver.logging.MockServerLogger, boolean, java.security.cert.Certificate[], io.netty.channel.Channel, org.mockserver.netty.websocketregistry.CallbackWebSocketServerHandler, org.mockserver.dashboard.DashboardWebSocketHandler, org.mockserver.netty.mcp.McpStreamableHttpHandler, org.mockserver.netty.unification.TraceContextHandler, org.mockserver.netty.unification.AltSvcHeaderHandler, org.mockserver.netty.grpc.GrpcToHttpResponseHandler, org.mockserver.netty.grpc.GrpcToHttpRequestHandler, org.mockserver.netty.HttpRequestHandler) method so both this initializer and the router can install it.

  • Constructor Details

  • Method Details

    • initChannel

      protected void initChannel(io.netty.handler.codec.http2.Http2StreamChannel ch)
      Specified by:
      initChannel in class io.netty.channel.ChannelInitializer<io.netty.handler.codec.http2.Http2StreamChannel>
    • installReAggregatingChain

      public static void installReAggregatingChain(io.netty.channel.ChannelPipeline pipeline, Configuration configuration, MockServerLogger mockServerLogger, boolean sslEnabled, Certificate[] clientCertificates, io.netty.channel.Channel channel, CallbackWebSocketServerHandler callbackWebSocketServerHandler, DashboardWebSocketHandler dashboardWebSocketHandler, McpStreamableHttpHandler mcpStreamableHttpHandler, TraceContextHandler traceContextHandler, AltSvcHeaderHandler altSvcHeaderHandler, GrpcToHttpResponseHandler grpcToHttpResponseHandler, GrpcToHttpRequestHandler grpcToHttpRequestHandler, HttpRequestHandler httpRequestHandler)
      Installs the re-aggregating chain into the given pipeline: converts HTTP/2 stream frames back into FullHttpRequest/FullHttpResponse and adds the downstream handler chain (WebSocket, MCP, gRPC codec, request handler). This is the pipeline every ordinary HTTP/2 stream uses.

      It is a static method so both initChannel(io.netty.handler.codec.http2.Http2StreamChannel) (when no bidi routing is possible) and GrpcBidiRouterHandler (for non-bidi streams on a bidi-enabled connection) can install it. public because GrpcBidiRouterHandler lives in a different package.

      Parameters:
      pipeline - the child channel's pipeline
      configuration - server configuration
      mockServerLogger - logger
      sslEnabled - whether TLS is enabled
      clientCertificates - client certificates (may be null)
      channel - the child channel (used for localAddress)
      callbackWebSocketServerHandler - sharable WebSocket callback handler
      dashboardWebSocketHandler - sharable dashboard WebSocket handler
      mcpStreamableHttpHandler - sharable MCP handler (may be null)
      traceContextHandler - sharable trace context handler
      altSvcHeaderHandler - sharable Alt-Svc header handler (may be null)
      grpcToHttpResponseHandler - sharable gRPC response handler (may be null)
      grpcToHttpRequestHandler - sharable gRPC request handler (may be null)
      httpRequestHandler - sharable HTTP request handler