use of io.netty.handler.codec.http2.Http2MultiplexHandler in project netty by netty.
the class Http2OrHttpHandler method configurePipeline.
@Override
protected void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception {
if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
ctx.pipeline().addLast(Http2FrameCodecBuilder.forServer().build());
ctx.pipeline().addLast(new Http2MultiplexHandler(new HelloWorldHttp2Handler()));
return;
}
if (ApplicationProtocolNames.HTTP_1_1.equals(protocol)) {
ctx.pipeline().addLast(new HttpServerCodec(), new HttpObjectAggregator(MAX_CONTENT_LENGTH), new HelloWorldHttp1Handler("ALPN Negotiation"));
return;
}
throw new IllegalStateException("unknown protocol: " + protocol);
}
use of io.netty.handler.codec.http2.Http2MultiplexHandler in project rest.li by linkedin.
the class Http2AlpnHandler method configurePipeline.
@Override
protected void configurePipeline(ChannelHandlerContext ctx, String protocol) {
switch(protocol) {
case ApplicationProtocolNames.HTTP_2:
ctx.pipeline().addLast(Http2FrameCodecBuilder.forClient().initialSettings(_http2Settings).build());
ctx.pipeline().addLast(new Http2MultiplexHandler(new UnsupportedHandler()));
_alpnPromise.setSuccess();
break;
default:
_alpnPromise.setFailure(new IllegalStateException("Unsupported protocol '" + protocol + "' is negotiated."));
}
}
use of io.netty.handler.codec.http2.Http2MultiplexHandler in project reactor-netty by reactor.
the class Http2PoolTest method acquireInvalidate.
@Test
void acquireInvalidate() {
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.invalidate().block(Duration.ofSeconds(1));
}
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(0);
for (PooledRef<Connection> slot : acquired) {
// second invalidate() should be ignored and ACQUIRED size should remain the same
slot.invalidate().block(Duration.ofSeconds(1));
}
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(0);
} finally {
channel.finishAndReleaseAll();
Connection.from(channel).dispose();
}
}
use of io.netty.handler.codec.http2.Http2MultiplexHandler in project reactor-netty by reactor.
the class HttpServerConfig method configureH2Pipeline.
static void configureH2Pipeline(ChannelPipeline p, boolean accessLogEnabled, @Nullable Function<AccessLogArgProvider, AccessLog> accessLog, @Nullable BiPredicate<HttpServerRequest, HttpServerResponse> compressPredicate, ServerCookieDecoder cookieDecoder, ServerCookieEncoder cookieEncoder, HttpServerFormDecoderProvider formDecoderProvider, @Nullable BiFunction<ConnectionInfo, HttpRequest, ConnectionInfo> forwardedHeaderHandler, Http2Settings http2Settings, ConnectionObserver listener, @Nullable BiFunction<? super Mono<Void>, ? super Connection, ? extends Mono<Void>> mapHandle, int minCompressionSize, ChannelOperations.OnSetup opsFactory, boolean validate) {
p.remove(NettyPipeline.ReactiveBridge);
Http2FrameCodecBuilder http2FrameCodecBuilder = Http2FrameCodecBuilder.forServer().validateHeaders(validate).initialSettings(http2Settings);
if (p.get(NettyPipeline.LoggingHandler) != null) {
http2FrameCodecBuilder.frameLogger(new Http2FrameLogger(LogLevel.DEBUG, "reactor.netty.http.server.h2"));
}
p.addLast(NettyPipeline.HttpCodec, http2FrameCodecBuilder.build()).addLast(NettyPipeline.H2MultiplexHandler, new Http2MultiplexHandler(new H2Codec(accessLogEnabled, accessLog, compressPredicate, cookieDecoder, cookieEncoder, formDecoderProvider, forwardedHeaderHandler, listener, mapHandle, minCompressionSize, opsFactory)));
}
use of io.netty.handler.codec.http2.Http2MultiplexHandler in project cxf by apache.
the class NettyHttpServletPipelineFactory method getDefaultHttp2ChannelPipeline.
protected ChannelPipeline getDefaultHttp2ChannelPipeline(Channel channel) throws Exception {
// Create a default pipeline implementation with HTTP/2 support
ChannelPipeline pipeline = channel.pipeline();
SslContext sslCtx = configureServerHttp2SSLOnDemand();
if (sslCtx != null) {
final SslHandler sslHandler = sslCtx.newHandler(channel.alloc());
LOG.log(Level.FINE, "Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
pipeline.addLast(sslHandler, new Http2OrHttpHandler());
return pipeline;
}
final UpgradeCodecFactory upgradeCodecFactory = new UpgradeCodecFactory() {
@Override
public UpgradeCodec newUpgradeCodec(CharSequence protocol) {
if (AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) {
return new Http2ServerUpgradeCodec(Http2FrameCodecBuilder.forServer().build(), new Http2MultiplexHandler(createHttp2ChannelInitializer()));
} else {
return null;
}
}
};
final HttpServerCodec sourceCodec = new HttpServerCodec();
final HttpServerUpgradeHandler upgradeHandler = new HttpServerUpgradeHandler(sourceCodec, upgradeCodecFactory);
final CleartextHttp2ServerUpgradeHandler cleartextUpgradeHandler = new CleartextHttp2ServerUpgradeHandler(sourceCodec, upgradeHandler, createHttp2ChannelInitializerPriorKnowledge());
pipeline.addLast(cleartextUpgradeHandler);
pipeline.addLast(new SimpleChannelInboundHandler<HttpMessage>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception {
// If this handler is hit then no upgrade has been attempted and the client is just talking HTTP
final ChannelPipeline pipeline = ctx.pipeline();
pipeline.addAfter(applicationExecutor, ctx.name(), "handler", getServletHandler());
pipeline.replace(this, "aggregator", new HttpObjectAggregator(maxChunkContentSize));
// Remove the following line if you don't want automatic content compression.
pipeline.addLast("deflater", new HttpContentCompressor());
// Set up the idle handler
pipeline.addLast("idle", new IdleStateHandler(nettyHttpServerEngine.getReadIdleTime(), nettyHttpServerEngine.getWriteIdleTime(), 0));
ctx.fireChannelRead(ReferenceCountUtil.retain(msg));
}
});
return pipeline;
}
Aggregations