Search in sources :

Example 6 with Http2MultiplexHandler

use of io.netty.handler.codec.http2.Http2MultiplexHandler in project ambry by linkedin.

the class Http2ChannelPoolHandler method channelCreated.

@Override
public void channelCreated(Channel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    SslHandler sslHandler = new SslHandler(sslFactory.createSSLEngine(host, port, SSLFactory.Mode.CLIENT));
    pipeline.addLast(sslHandler);
    if (http2PeerCertificateValidator != null) {
        pipeline.addLast(http2PeerCertificateValidator);
    }
    pipeline.addLast(Http2FrameCodecBuilder.forClient().initialSettings(Http2Settings.defaultSettings().maxFrameSize(http2ClientConfig.http2FrameMaxSize).initialWindowSize(http2ClientConfig.http2InitialWindowSize)).frameLogger(new Http2FrameLogger(LogLevel.DEBUG, "client")).build());
    pipeline.addLast(new Http2MultiplexHandler(new ChannelInboundHandlerAdapter()));
    pipeline.addLast(connectionInboundExceptionHandler);
}
Also used : Http2MultiplexHandler(io.netty.handler.codec.http2.Http2MultiplexHandler) Http2FrameLogger(io.netty.handler.codec.http2.Http2FrameLogger) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter)

Example 7 with Http2MultiplexHandler

use of io.netty.handler.codec.http2.Http2MultiplexHandler in project ambry by linkedin.

the class StorageServerNettyChannelInitializer method initChannel.

@Override
protected void initChannel(SocketChannel ch) throws Exception {
    // To honor http2 window size, WriteBufferWaterMark.high() should be greater or equal to http2 window size.
    // Also see: https://github.com/netty/netty/issues/10193
    // https://stackoverflow.com/questions/25281124/netty-4-high-and-low-write-watermarks
    ch.config().setSendBufferSize(http2ClientConfig.nettySendBufferSize).setReceiveBufferSize(http2ClientConfig.nettyReceiveBufferSize).setWriteBufferWaterMark(new WriteBufferWaterMark(http2ClientConfig.http2InitialWindowSize / 2, http2ClientConfig.http2InitialWindowSize));
    // If channel handler implementations are not annotated with @Sharable, Netty creates a new instance of every class
    // in the pipeline for every connection.
    // i.e. if there are a 1000 active connections there will be a 1000 NettyMessageProcessor instances.
    ChannelPipeline pipeline = ch.pipeline();
    // connection stats handler to track connection related metrics
    pipeline.addLast("ConnectionStatsHandler", connectionStatsHandler);
    InetSocketAddress peerAddress = ch.remoteAddress();
    String peerHost = peerAddress.getHostName();
    int peerPort = peerAddress.getPort();
    SslHandler sslHandler = new SslHandler(sslFactory.createSSLEngine(peerHost, peerPort, SSLFactory.Mode.SERVER));
    pipeline.addLast("SslHandler", sslHandler);
    pipeline.addLast("SecurityChecker", serverSecurityHandler);
    pipeline.addLast("Http2FrameCodec", Http2FrameCodecBuilder.forServer().initialSettings(Http2Settings.defaultSettings().maxFrameSize(http2ClientConfig.http2FrameMaxSize).initialWindowSize(http2ClientConfig.http2InitialWindowSize)).frameLogger(new Http2FrameLogger(LogLevel.DEBUG, "server")).build());
    pipeline.addLast("Http2MultiplexHandler", new Http2MultiplexHandler(http2ServerStreamHandler));
    pipeline.addLast("CloseOnExceptionHandler", closeOnExceptionHandler);
}
Also used : Http2MultiplexHandler(io.netty.handler.codec.http2.Http2MultiplexHandler) InetSocketAddress(java.net.InetSocketAddress) Http2FrameLogger(io.netty.handler.codec.http2.Http2FrameLogger) WriteBufferWaterMark(io.netty.channel.WriteBufferWaterMark) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler)

Example 8 with Http2MultiplexHandler

use of io.netty.handler.codec.http2.Http2MultiplexHandler in project netty by netty.

the class Http2ClientFrameInitializer method initChannel.

@Override
protected void initChannel(Channel ch) throws Exception {
    // ensure that our 'trust all' SSL handler is the first in the pipeline if SSL is enabled.
    if (sslCtx != null) {
        ch.pipeline().addFirst(sslCtx.newHandler(ch.alloc()));
    }
    final Http2FrameCodec http2FrameCodec = Http2FrameCodecBuilder.forClient().initialSettings(// this is the default, but shows it can be changed.
    Http2Settings.defaultSettings()).build();
    ch.pipeline().addLast(http2FrameCodec);
    ch.pipeline().addLast(new Http2MultiplexHandler(new SimpleChannelInboundHandler() {

        @Override
        protected void channelRead0(ChannelHandlerContext ctx, Object msg) {
        // NOOP (this is the handler for 'inbound' streams, which is not relevant in this example)
        }
    }));
}
Also used : SimpleChannelInboundHandler(io.netty.channel.SimpleChannelInboundHandler) Http2MultiplexHandler(io.netty.handler.codec.http2.Http2MultiplexHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Http2FrameCodec(io.netty.handler.codec.http2.Http2FrameCodec)

Example 9 with Http2MultiplexHandler

use of io.netty.handler.codec.http2.Http2MultiplexHandler in project rest.li by linkedin.

the class Http2ChannelInitializer method configureClearText.

/**
 * Configure the pipeline for HTTP/2 clear text.
 */
private void configureClearText(NioSocketChannel channel) {
    final HttpClientCodec sourceCodec = new HttpClientCodec(_maxInitialLineLength, _maxHeaderSize, _maxChunkSize);
    UnsupportedHandler unsupportedHandler = new UnsupportedHandler();
    Http2MultiplexHandler multiplexHandler = new Http2MultiplexHandler(unsupportedHandler, unsupportedHandler);
    Http2ClientUpgradeCodec upgradeCodec = new Http2ClientUpgradeCodec((Http2ConnectionHandler) Http2FrameCodecBuilder.forClient().initialSettings(createHttp2Settings()).build(), multiplexHandler);
    final ChannelPromise upgradePromise = channel.newPromise();
    channel.attr(NettyChannelAttributes.INITIALIZATION_FUTURE).set(upgradePromise);
    channel.pipeline().addLast(sourceCodec);
    channel.pipeline().addLast(new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, _maxContentLength));
    channel.pipeline().addLast(new Http2ProtocolUpgradeHandler(upgradePromise));
}
Also used : UnsupportedHandler(com.linkedin.r2.netty.handler.http2.UnsupportedHandler) Http2MultiplexHandler(io.netty.handler.codec.http2.Http2MultiplexHandler) Http2ProtocolUpgradeHandler(com.linkedin.r2.netty.handler.http2.Http2ProtocolUpgradeHandler) Http2ClientUpgradeCodec(io.netty.handler.codec.http2.Http2ClientUpgradeCodec) ChannelPromise(io.netty.channel.ChannelPromise) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) HttpClientUpgradeHandler(io.netty.handler.codec.http.HttpClientUpgradeHandler)

Example 10 with Http2MultiplexHandler

use of io.netty.handler.codec.http2.Http2MultiplexHandler in project zuul by Netflix.

the class Http2OrHttpHandler method configureHttp2.

private void configureHttp2(ChannelPipeline pipeline) {
    // setup the initial stream settings for the server to use.
    Http2Settings settings = new Http2Settings().maxConcurrentStreams(maxConcurrentStreams).initialWindowSize(initialWindowSize).headerTableSize(maxHeaderTableSize).maxHeaderListSize(maxHeaderListSize);
    Http2FrameCodec frameCodec = Http2FrameCodecBuilder.forServer().frameLogger(FRAME_LOGGER).initialSettings(settings).validateHeaders(true).build();
    Http2Connection conn = frameCodec.connection();
    // Use the uniform byte distributor until https://github.com/netty/netty/issues/10525 is fixed.
    conn.remote().flowController(new DefaultHttp2RemoteFlowController(conn, new UniformStreamByteDistributor(conn)));
    Http2MultiplexHandler multiplexHandler = new Http2MultiplexHandler(http2StreamHandler);
    // The frame codec MUST be in the pipeline.
    pipeline.addBefore("codec_placeholder", /* name= */
    null, frameCodec);
    pipeline.replace("codec_placeholder", HTTP_CODEC_HANDLER_NAME, multiplexHandler);
}
Also used : Http2MultiplexHandler(io.netty.handler.codec.http2.Http2MultiplexHandler) Http2Connection(io.netty.handler.codec.http2.Http2Connection) DefaultHttp2RemoteFlowController(io.netty.handler.codec.http2.DefaultHttp2RemoteFlowController) Http2Settings(io.netty.handler.codec.http2.Http2Settings) Http2FrameCodec(io.netty.handler.codec.http2.Http2FrameCodec) UniformStreamByteDistributor(io.netty.handler.codec.http2.UniformStreamByteDistributor)

Aggregations

Http2MultiplexHandler (io.netty.handler.codec.http2.Http2MultiplexHandler)12 Http2FrameLogger (io.netty.handler.codec.http2.Http2FrameLogger)4 ChannelPipeline (io.netty.channel.ChannelPipeline)3 SslHandler (io.netty.handler.ssl.SslHandler)3 ChannelHandlerAdapter (io.netty.channel.ChannelHandlerAdapter)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)2 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)2 Http2FrameCodec (io.netty.handler.codec.http2.Http2FrameCodec)2 Http2FrameCodecBuilder (io.netty.handler.codec.http2.Http2FrameCodecBuilder)2 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2 Connection (reactor.netty.Connection)2 PoolConfig (reactor.netty.internal.shaded.reactor.pool.PoolConfig)2 PooledRef (reactor.netty.internal.shaded.reactor.pool.PooledRef)2 Http2ProtocolUpgradeHandler (com.linkedin.r2.netty.handler.http2.Http2ProtocolUpgradeHandler)1 UnsupportedHandler (com.linkedin.r2.netty.handler.http2.UnsupportedHandler)1 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)1 ChannelPromise (io.netty.channel.ChannelPromise)1