Search in sources :

Example 11 with Http2MultiplexHandler

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

the class HttpClientConfig method configureHttp2Pipeline.

static void configureHttp2Pipeline(ChannelPipeline p, boolean acceptGzip, HttpResponseDecoderSpec decoder, Http2Settings http2Settings, ConnectionObserver observer) {
    Http2FrameCodecBuilder http2FrameCodecBuilder = Http2FrameCodecBuilder.forClient().validateHeaders(decoder.validateHeaders()).initialSettings(http2Settings);
    if (p.get(NettyPipeline.LoggingHandler) != null) {
        http2FrameCodecBuilder.frameLogger(new Http2FrameLogger(LogLevel.DEBUG, "reactor.netty.http.client.h2"));
    }
    p.addBefore(NettyPipeline.ReactiveBridge, NettyPipeline.HttpCodec, http2FrameCodecBuilder.build()).addBefore(NettyPipeline.ReactiveBridge, NettyPipeline.H2MultiplexHandler, new Http2MultiplexHandler(new H2Codec(acceptGzip))).addBefore(NettyPipeline.ReactiveBridge, NettyPipeline.HttpTrafficHandler, new HttpTrafficHandler(observer));
}
Also used : Http2MultiplexHandler(io.netty.handler.codec.http2.Http2MultiplexHandler) Http2FrameCodecBuilder(io.netty.handler.codec.http2.Http2FrameCodecBuilder) Http2FrameLogger(io.netty.handler.codec.http2.Http2FrameLogger)

Example 12 with Http2MultiplexHandler

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

the class Http2PoolTest method acquireRelease.

@Test
void acquireRelease() {
    EmbeddedChannel channel = new EmbeddedChannel(Http2FrameCodecBuilder.forClient().build(), new Http2MultiplexHandler(new ChannelHandlerAdapter() {
    }));
    PoolBuilder<Connection, PoolConfig<Connection>> poolBuilder = PoolBuilder.from(Mono.just(Connection.from(channel))).idleResourceReuseLruOrder().maxPendingAcquireUnbounded().sizeBetween(0, 1);
    InstrumentedPool<Connection> http2Pool = poolBuilder.build(config -> new Http2Pool(config, -1));
    try {
        List<PooledRef<Connection>> acquired = new ArrayList<>();
        http2Pool.acquire().subscribe(acquired::add);
        http2Pool.acquire().subscribe(acquired::add);
        http2Pool.acquire().subscribe(acquired::add);
        assertThat(acquired).hasSize(3);
        assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(3);
        for (PooledRef<Connection> slot : acquired) {
            slot.release().block(Duration.ofSeconds(1));
        }
        assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(0);
        for (PooledRef<Connection> slot : acquired) {
            // second release() should be ignored and ACQUIRED size should remain the same
            slot.release().block(Duration.ofSeconds(1));
        }
        assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(0);
    } finally {
        channel.finishAndReleaseAll();
        Connection.from(channel).dispose();
    }
}
Also used : Connection(reactor.netty.Connection) ArrayList(java.util.ArrayList) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelHandlerAdapter(io.netty.channel.ChannelHandlerAdapter) Http2MultiplexHandler(io.netty.handler.codec.http2.Http2MultiplexHandler) PoolConfig(reactor.netty.internal.shaded.reactor.pool.PoolConfig) PooledRef(reactor.netty.internal.shaded.reactor.pool.PooledRef) Test(org.junit.jupiter.api.Test)

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