io.netty.handler.codec.http2.CleartextHttp2ServerUpgradeHandler Java Examples

The following examples show how to use io.netty.handler.codec.http2.CleartextHttp2ServerUpgradeHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpServerConfig.java    From reactor-netty with Apache License 2.0 4 votes vote down vote up
static void configureHttp11OrH2CleartextPipeline(ChannelPipeline p,
		@Nullable BiPredicate<HttpServerRequest, HttpServerResponse> compressPredicate,
		ServerCookieDecoder cookieDecoder,
		ServerCookieEncoder cookieEncoder,
		HttpRequestDecoderSpec decoder,
		boolean forwarded,
		Http2Settings http2Settings,
		ConnectionObserver listener,
		@Nullable Supplier<? extends ChannelMetricsRecorder> metricsRecorder,
		int minCompressionSize,
		ChannelOperations.OnSetup opsFactory,
		@Nullable Function<String, String> uriTagValue) {
	HttpServerCodec httpServerCodec =
			new HttpServerCodec(decoder.maxInitialLineLength(), decoder.maxHeaderSize(),
					decoder.maxChunkSize(), decoder.validateHeaders(), decoder.initialBufferSize());

	Http11OrH2CleartextCodec
			upgrader = new Http11OrH2CleartextCodec(cookieDecoder, cookieEncoder, p.get(NettyPipeline.LoggingHandler) != null,
					forwarded, http2Settings, listener, opsFactory, decoder.validateHeaders());

	ChannelHandler http2ServerHandler = new H2CleartextCodec(upgrader);
	CleartextHttp2ServerUpgradeHandler h2cUpgradeHandler = new CleartextHttp2ServerUpgradeHandler(
			httpServerCodec,
			new HttpServerUpgradeHandler(httpServerCodec, upgrader, decoder.h2cMaxContentLength()),
			http2ServerHandler);

	p.addBefore(NettyPipeline.ReactiveBridge,
	            NettyPipeline.H2CUpgradeHandler, h2cUpgradeHandler)
	 .addBefore(NettyPipeline.ReactiveBridge,
	            NettyPipeline.HttpTrafficHandler,
	            new HttpTrafficHandler(listener, forwarded, compressPredicate, cookieEncoder, cookieDecoder));

	if (ACCESS_LOG) {
		p.addAfter(NettyPipeline.H2CUpgradeHandler, NettyPipeline.AccessLogHandler, new AccessLogHandler());
	}

	boolean alwaysCompress = compressPredicate == null && minCompressionSize == 0;

	if (alwaysCompress) {
		p.addBefore(NettyPipeline.HttpTrafficHandler, NettyPipeline.CompressionHandler, new SimpleCompressionHandler());
	}

	if (metricsRecorder != null) {
		ChannelMetricsRecorder channelMetricsRecorder = metricsRecorder.get();
		if (channelMetricsRecorder instanceof HttpServerMetricsRecorder) {
			p.addAfter(NettyPipeline.HttpTrafficHandler, NettyPipeline.HttpMetricsHandler,
			           new HttpServerMetricsHandler((HttpServerMetricsRecorder) channelMetricsRecorder, uriTagValue));
			if (channelMetricsRecorder instanceof MicrometerHttpServerMetricsRecorder) {
				// MicrometerHttpServerMetricsRecorder does not implement metrics on protocol level
				// ChannelMetricsHandler will be removed from the pipeline
				p.remove(NettyPipeline.ChannelMetricsHandler);
			}
		}
	}
}