use of io.netty.handler.codec.http2.Http2FrameCodec in project netty by netty.
the class Http2FrameCodecTest method flowControlShouldBeResilientToMissingStreams.
@Test
public void flowControlShouldBeResilientToMissingStreams() throws Http2Exception {
Http2Connection conn = new DefaultHttp2Connection(true);
Http2ConnectionEncoder enc = new DefaultHttp2ConnectionEncoder(conn, new DefaultHttp2FrameWriter());
Http2ConnectionDecoder dec = new DefaultHttp2ConnectionDecoder(conn, enc, new DefaultHttp2FrameReader());
Http2FrameCodec codec = new Http2FrameCodec(enc, dec, new Http2Settings(), false);
EmbeddedChannel em = new EmbeddedChannel(codec);
// We call #consumeBytes on a stream id which has not been seen yet to emulate the case
// where a stream is deregistered which in reality can happen in response to a RST.
assertFalse(codec.consumeBytes(1, 1));
assertTrue(em.finishAndReleaseAll());
}
use of io.netty.handler.codec.http2.Http2FrameCodec 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.Http2FrameCodec 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.Http2FrameCodec 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