private void handleHttp2Settings(ChannelHandlerContext ctx, Http2Settings h2settings) { if (h2settings.isEmpty()) { logger.trace("{} HTTP/2 settings: <empty>", ctx.channel()); } else { logger.debug("{} HTTP/2 settings: {}", ctx.channel(), h2settings); } if (protocol == H1) { protocol = H2; } else if (protocol == H1C) { protocol = H2C; } final Http2ConnectionHandler handler = ctx.pipeline().get(Http2ConnectionHandler.class); if (responseEncoder == null) { responseEncoder = new Http2ObjectEncoder(handler.encoder()); } else if (responseEncoder instanceof Http1ObjectEncoder) { responseEncoder.close(); responseEncoder = new Http2ObjectEncoder(handler.encoder()); } }
private Http2ConnectionHandler newHttp2ConnectionHandler(ChannelPipeline pipeline) { final Http2Connection conn = new DefaultHttp2Connection(true); conn.addListener(new Http2GoAwayListener(pipeline.channel())); Http2FrameReader reader = new DefaultHttp2FrameReader(true); Http2FrameWriter writer = new DefaultHttp2FrameWriter(); Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(conn, writer); Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(conn, encoder, reader); final Http2ConnectionHandler handler = new Http2ServerConnectionHandler(decoder, encoder, new Http2Settings()); // Setup post build options final Http2RequestDecoder listener = new Http2RequestDecoder(config, pipeline.channel(), handler.encoder()); handler.connection().addListener(listener); handler.decoder().frameListener(listener); handler.gracefulShutdownTimeoutMillis(config.idleTimeoutMillis()); return handler; }
private Http2ConnectionHandler newHttp2ConnectionHandler(final ChannelPipeline p) { DefaultHttp2Connection connection = new DefaultHttp2Connection(true); InboundHttp2ToHttpAdapter listener = new InboundHttp2ToHttpAdapterBuilder(connection) .propagateSettings(false) .validateHttpHeaders(false) .maxContentLength(maxContentLength) .build(); HttpToHttp2ConnectionHandler http2handler = new HttpToHttp2ConnectionHandlerBuilder() .frameListener(listener) .frameLogger(new Http2FrameLogger(LogLevel.DEBUG)) .connection(connection) .build(); return http2handler; }
@BeforeClass public static void setUp() throws IOException, URISyntaxException, TimeoutException { CLUSTER = new MiniDFSCluster.Builder(CONF).numDataNodes(1).build(); CLUSTER.waitActive(); RESPONSE_HANDLER = new Http2ResponseHandler(); Bootstrap bootstrap = new Bootstrap() .group(WORKER_GROUP) .channel(NioSocketChannel.class) .remoteAddress("127.0.0.1", CLUSTER.getDataNodes().get(0).getInfoPort()) .handler(new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel ch) throws Exception { Http2Connection connection = new DefaultHttp2Connection(false); Http2ConnectionHandler connectionHandler = new HttpToHttp2ConnectionHandler(connection, frameReader(), frameWriter(), new DelegatingDecompressorFrameListener( connection, new InboundHttp2ToHttpAdapter.Builder( connection).maxContentLength(Integer.MAX_VALUE) .propagateSettings(true).build())); ch.pipeline().addLast(connectionHandler, RESPONSE_HANDLER); } }); CHANNEL = bootstrap.connect().syncUninterruptibly().channel(); }
@Override protected Http2ConnectionHandler createHttp2RequestHandler() { return new HelloWorldHttp2Handler(); }