Java 类io.netty.handler.codec.http2.Http2ConnectionHandler 实例源码

项目:armeria    文件:HttpServerHandler.java   
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());
    }
}
项目:armeria    文件:HttpServerPipelineConfigurator.java   
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;
    }
项目:jooby    文件:NettyPipeline.java   
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;
}
项目:aliyun-oss-hadoop-fs    文件:TestDtpHttp2.java   
@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();

}
项目:netty-cookbook    文件:Http2OrHttpHandler.java   
@Override
protected Http2ConnectionHandler createHttp2RequestHandler() {
    return new HelloWorldHttp2Handler();
}