use of io.netty.handler.codec.http2.Http2MultiplexHandler in project ambry by linkedin.
the class Http2ChannelPoolHandler method channelCreated.
@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);
if (http2PeerCertificateValidator != null) {
pipeline.addLast(http2PeerCertificateValidator);
}
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()));
pipeline.addLast(connectionInboundExceptionHandler);
}
use of io.netty.handler.codec.http2.Http2MultiplexHandler 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);
}
use of io.netty.handler.codec.http2.Http2MultiplexHandler 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)
}
}));
}
use of io.netty.handler.codec.http2.Http2MultiplexHandler in project rest.li by linkedin.
the class Http2ChannelInitializer method configureClearText.
/**
* Configure the pipeline for HTTP/2 clear text.
*/
private void configureClearText(NioSocketChannel channel) {
final HttpClientCodec sourceCodec = new HttpClientCodec(_maxInitialLineLength, _maxHeaderSize, _maxChunkSize);
UnsupportedHandler unsupportedHandler = new UnsupportedHandler();
Http2MultiplexHandler multiplexHandler = new Http2MultiplexHandler(unsupportedHandler, unsupportedHandler);
Http2ClientUpgradeCodec upgradeCodec = new Http2ClientUpgradeCodec((Http2ConnectionHandler) Http2FrameCodecBuilder.forClient().initialSettings(createHttp2Settings()).build(), multiplexHandler);
final ChannelPromise upgradePromise = channel.newPromise();
channel.attr(NettyChannelAttributes.INITIALIZATION_FUTURE).set(upgradePromise);
channel.pipeline().addLast(sourceCodec);
channel.pipeline().addLast(new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, _maxContentLength));
channel.pipeline().addLast(new Http2ProtocolUpgradeHandler(upgradePromise));
}
use of io.netty.handler.codec.http2.Http2MultiplexHandler 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);
}
Aggregations