io.netty.handler.codec.http2.Http2MultiplexHandler Java Examples
The following examples show how to use
io.netty.handler.codec.http2.Http2MultiplexHandler.
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: H2ServerParentChannelInitializer.java From servicetalk with Apache License 2.0 | 6 votes |
@Override public void init(final Channel channel) { final Http2FrameCodecBuilder multiplexCodecBuilder = forServer() // We do not want close to trigger graceful closure (go away), instead when user triggers a graceful // close, we do the appropriate go away handling. .decoupleCloseAndGoAway(true) // We don't want to rely upon Netty to manage the graceful close timeout, because we expect // the user to apply their own timeout at the call site. .gracefulShutdownTimeoutMillis(-1); final BiPredicate<CharSequence, CharSequence> headersSensitivityDetector = config.headersSensitivityDetector(); multiplexCodecBuilder.headerSensitivityDetector(headersSensitivityDetector::test); final String frameLoggerName = config.frameLoggerName(); if (frameLoggerName != null) { multiplexCodecBuilder.frameLogger(new Http2FrameLogger(TRACE, frameLoggerName)); } // TODO(scott): more configuration. header validation, settings stream, etc... channel.pipeline().addLast(multiplexCodecBuilder.build(), new Http2MultiplexHandler(streamChannelInitializer)); }
Example #2
Source File: H2PriorKnowledgeFeatureParityTest.java From servicetalk with Apache License 2.0 | 6 votes |
private InetSocketAddress bindH2Server(ChannelHandler childChannelHandler, Consumer<ChannelPipeline> parentChannelInitializer) { ServerBootstrap sb = new ServerBootstrap(); sb.group(serverEventLoopGroup); sb.channel(serverChannel(serverEventLoopGroup, InetSocketAddress.class)); sb.childHandler(new ChannelInitializer<Channel>() { @Override protected void initChannel(final Channel ch) { ch.pipeline().addLast( Http2FrameCodecBuilder.forServer().build(), new Http2MultiplexHandler(childChannelHandler)); parentChannelInitializer.accept(ch.pipeline()); } }); serverAcceptorChannel = sb.bind(localAddress(0)).syncUninterruptibly().channel(); return (InetSocketAddress) serverAcceptorChannel.localAddress(); }
Example #3
Source File: HttpClientConfig.java From reactor-netty with Apache License 2.0 | 6 votes |
static void configureHttp2Pipeline(ChannelPipeline p, 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())) .addBefore(NettyPipeline.ReactiveBridge, NettyPipeline.HttpTrafficHandler, new HttpTrafficHandler(observer)); }
Example #4
Source File: HttpServerConfig.java From reactor-netty with Apache License 2.0 | 6 votes |
static void configureH2Pipeline(ChannelPipeline p, ServerCookieDecoder cookieDecoder, ServerCookieEncoder cookieEncoder, boolean forwarded, Http2Settings http2Settings, ConnectionObserver listener, 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(opsFactory, listener, forwarded, cookieEncoder, cookieDecoder))); }
Example #5
Source File: Http2OrHttpHandler.java From zuul with Apache License 2.0 | 6 votes |
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(); 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); }
Example #6
Source File: H2ClientParentChannelInitializer.java From servicetalk with Apache License 2.0 | 5 votes |
@Override public void init(final Channel channel) { final Http2FrameCodecBuilder multiplexCodecBuilder = forClient() // We do not want close to trigger graceful closure (go away), instead when user triggers a graceful // close, we do the appropriate go away handling. .decoupleCloseAndGoAway(true) // The max concurrent streams is made available via a publisher and may be consumed asynchronously // (e.g. when offloading is enabled), so we manually control the SETTINGS ACK frames. .autoAckSettingsFrame(false) // We don't want to rely upon Netty to manage the graceful close timeout, because we expect // the user to apply their own timeout at the call site. .gracefulShutdownTimeoutMillis(-1); // Notify server that this client does not support server push and request it to be disabled. multiplexCodecBuilder.initialSettings().pushEnabled(false).maxConcurrentStreams(0L); final BiPredicate<CharSequence, CharSequence> headersSensitivityDetector = config.headersSensitivityDetector(); multiplexCodecBuilder.headerSensitivityDetector(headersSensitivityDetector::test); final String frameLoggerName = config.frameLoggerName(); if (frameLoggerName != null) { multiplexCodecBuilder.frameLogger(new Http2FrameLogger(TRACE, frameLoggerName)); } // TODO(scott): more configuration. header validation, settings stream, etc... channel.pipeline().addLast(multiplexCodecBuilder.build(), new Http2MultiplexHandler(H2PushStreamHandler.INSTANCE)); }
Example #7
Source File: Http2TestUtils.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
public static EmbeddedChannel newHttp2Channel(ChannelHandler channelHandler) { Http2FrameCodec http2FrameCodec = Http2FrameCodecBuilder.forClient().initialSettings( Http2Settings.defaultSettings().initialWindowSize(INITIAL_WINDOW_SIZE)) .frameLogger(new Http2FrameLogger(LogLevel.DEBUG)).build(); EmbeddedChannel channel = new EmbeddedChannel(http2FrameCodec, new Http2MultiplexHandler(channelHandler)); channel.attr(ChannelAttributeKey.HTTP2_CONNECTION).set(http2FrameCodec.connection()); channel.attr(ChannelAttributeKey.HTTP2_INITIAL_WINDOW_SIZE).set(INITIAL_WINDOW_SIZE); channel.attr(ChannelAttributeKey.PROTOCOL_FUTURE).set(CompletableFuture.completedFuture(Protocol.HTTP2)); return channel; }
Example #8
Source File: HttpClientConfig.java From reactor-netty with Apache License 2.0 | 5 votes |
@Override public void handlerAdded(ChannelHandlerContext ctx) { ChannelPipeline pipeline = ctx.pipeline(); pipeline.addAfter(ctx.name(), NettyPipeline.HttpCodec, http2FrameCodec) .addAfter(NettyPipeline.HttpCodec, NettyPipeline.H2MultiplexHandler, new Http2MultiplexHandler(new H2Codec(opsFactory), new H2Codec(opsFactory))); if (pipeline.get(NettyPipeline.HttpDecompressor) != null) { pipeline.remove(NettyPipeline.HttpDecompressor); } pipeline.remove(NettyPipeline.ReactiveBridge); pipeline.remove(this); }
Example #9
Source File: HttpServerConfig.java From reactor-netty with Apache License 2.0 | 5 votes |
@Override public void handlerAdded(ChannelHandlerContext ctx) { ChannelPipeline pipeline = ctx.pipeline(); pipeline.addAfter(ctx.name(), NettyPipeline.HttpCodec, upgrader.http2FrameCodec) .addAfter(NettyPipeline.HttpCodec, NettyPipeline.H2MultiplexHandler, new Http2MultiplexHandler(upgrader)) .remove(this); if (pipeline.get(NettyPipeline.AccessLogHandler) != null){ pipeline.remove(NettyPipeline.AccessLogHandler); } if (pipeline.get(NettyPipeline.CompressionHandler) != null) { pipeline.remove(NettyPipeline.CompressionHandler); } pipeline.remove(NettyPipeline.HttpTrafficHandler); pipeline.remove(NettyPipeline.ReactiveBridge); }
Example #10
Source File: HttpServerConfig.java From reactor-netty with Apache License 2.0 | 5 votes |
@Override @Nullable public HttpServerUpgradeHandler.UpgradeCodec newUpgradeCodec(CharSequence protocol) { if (AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) { return new Http2ServerUpgradeCodec(http2FrameCodec, new Http2MultiplexHandler(this)); } else { return null; } }
Example #11
Source File: Http2ChannelPoolHandler.java From ambry with Apache License 2.0 | 5 votes |
@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); 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())); }
Example #12
Source File: StorageServerNettyChannelInitializer.java From ambry with Apache License 2.0 | 5 votes |
@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); }
Example #13
Source File: MultiplexedChannelRecordTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
private EmbeddedChannel newHttp2Channel() { EmbeddedChannel channel = new EmbeddedChannel(Http2FrameCodecBuilder.forClient().build(), new Http2MultiplexHandler(new NoOpHandler())); channel.attr(ChannelAttributeKey.PROTOCOL_FUTURE).set(CompletableFuture.completedFuture(Protocol.HTTP2)); return channel; }
Example #14
Source File: MultiplexedChannelRecordTest.java From ambry with Apache License 2.0 | 4 votes |
static EmbeddedChannel newHttp2Channel() { EmbeddedChannel channel = new EmbeddedChannel(Http2FrameCodecBuilder.forClient().build(), new Http2MultiplexHandler(new NoOpHandler())); return channel; }