Search in sources :

Example 1 with Http2FrameCodec

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

the class Http2FrameCodecTest method flowControlShouldBeResilientToMissingStreams.

@Test
public void flowControlShouldBeResilientToMissingStreams() throws Http2Exception {
    Http2Connection conn = new DefaultHttp2Connection(true);
    Http2ConnectionEncoder enc = new DefaultHttp2ConnectionEncoder(conn, new DefaultHttp2FrameWriter());
    Http2ConnectionDecoder dec = new DefaultHttp2ConnectionDecoder(conn, enc, new DefaultHttp2FrameReader());
    Http2FrameCodec codec = new Http2FrameCodec(enc, dec, new Http2Settings(), false);
    EmbeddedChannel em = new EmbeddedChannel(codec);
    // We call #consumeBytes on a stream id which has not been seen yet to emulate the case
    // where a stream is deregistered which in reality can happen in response to a RST.
    assertFalse(codec.consumeBytes(1, 1));
    assertTrue(em.finishAndReleaseAll());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Http2TestUtil.anyHttp2Settings(io.netty.handler.codec.http2.Http2TestUtil.anyHttp2Settings) Test(org.junit.jupiter.api.Test)

Example 2 with Http2FrameCodec

use of io.netty.handler.codec.http2.Http2FrameCodec 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 3 with Http2FrameCodec

use of io.netty.handler.codec.http2.Http2FrameCodec 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 4 with Http2FrameCodec

use of io.netty.handler.codec.http2.Http2FrameCodec 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)3 Http2FrameCodec (io.netty.handler.codec.http2.Http2FrameCodec)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 SimpleChannelInboundHandler (io.netty.channel.SimpleChannelInboundHandler)1 WriteBufferWaterMark (io.netty.channel.WriteBufferWaterMark)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 DefaultHttp2RemoteFlowController (io.netty.handler.codec.http2.DefaultHttp2RemoteFlowController)1 Http2Connection (io.netty.handler.codec.http2.Http2Connection)1 Http2FrameLogger (io.netty.handler.codec.http2.Http2FrameLogger)1 Http2Settings (io.netty.handler.codec.http2.Http2Settings)1 Http2TestUtil.anyHttp2Settings (io.netty.handler.codec.http2.Http2TestUtil.anyHttp2Settings)1 UniformStreamByteDistributor (io.netty.handler.codec.http2.UniformStreamByteDistributor)1 SslHandler (io.netty.handler.ssl.SslHandler)1 InetSocketAddress (java.net.InetSocketAddress)1 Test (org.junit.jupiter.api.Test)1