类 io.netty.handler.codec.http2.HttpToHttp2ConnectionHandler 源码实例Demo

下面列出了怎么用 io.netty.handler.codec.http2.HttpToHttp2ConnectionHandler 的API类实例代码及写法,或者点击链接到github查看源代码。


@Override
public void initChannel(SocketChannel ch) throws Exception {
    final Http2Connection connection = new DefaultHttp2Connection(false);

    connectionHandler = new HttpToHttp2ConnectionHandler(connection,
            frameReader(),
            frameWriter(),
            new DelegatingDecompressorFrameListener(connection,
                    new InboundHttp2ToHttpAdapter.Builder(connection)
                            .maxContentLength(maxContentLength)
                            .propagateSettings(true)
                            .build()));
    responseHandler = new HttpResponseHandler();
    settingsHandler = new Http2SettingsHandler(ch.newPromise());
    if (sslCtx != null) {
        configureSsl(ch);
    } else {
        configureClearText(ch);
    }
}
 

@Override
public void initChannel(SocketChannel ch) throws Exception {
    final Http2Connection connection = new DefaultHttp2Connection(false);
    final Http2FrameWriter frameWriter = frameWriter();
    connectionHandler = new HttpToHttp2ConnectionHandler(connection,
            frameReader(),
            frameWriter,
            new DelegatingDecompressorFrameListener(connection,
                    new InboundHttp2ToHttpAdapter.Builder(connection)
                            .maxContentLength(maxContentLength)
                            .propagateSettings(true)
                            .build()));
    responseHandler = new HttpResponseHandler();
    settingsHandler = new Http2SettingsHandler(ch.newPromise());
    configureClearText(ch);
}
 
源代码3 项目: armeria   文件: THttp2Client.java

@Override
public void initChannel(SocketChannel ch) throws Exception {
    final ChannelPipeline p = ch.pipeline();
    final Http2Connection conn = new DefaultHttp2Connection(false);
    final HttpToHttp2ConnectionHandler connHandler = new HttpToHttp2ConnectionHandlerBuilder()
            .connection(conn)
            .frameListener(new DelegatingDecompressorFrameListener(
                    conn,
                    new InboundHttp2ToHttpAdapterBuilder(conn)
                            .maxContentLength(Integer.MAX_VALUE)
                            .propagateSettings(true).build()))
            .build();

    clientHandler = new THttp2ClientHandler(ch.eventLoop());

    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(p.channel().alloc()));
        p.addLast(connHandler);
        configureEndOfPipeline(p);
    } else {
        final HttpClientCodec sourceCodec = new HttpClientCodec();
        final HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(
                sourceCodec, new Http2ClientUpgradeCodec(connHandler), 65536);

        p.addLast(sourceCodec, upgradeHandler, new UpgradeRequestHandler());
    }
}
 
源代码4 项目: tutorials   文件: Http2Util.java

public static ApplicationProtocolNegotiationHandler getClientAPNHandler(int maxContentLength, Http2SettingsHandler settingsHandler, Http2ClientResponseHandler responseHandler) {
    final Http2FrameLogger logger = new Http2FrameLogger(INFO, Http2Util.class);
    final Http2Connection connection = new DefaultHttp2Connection(false);

    HttpToHttp2ConnectionHandler connectionHandler = new HttpToHttp2ConnectionHandlerBuilder()
        .frameListener(new DelegatingDecompressorFrameListener(connection, new InboundHttp2ToHttpAdapterBuilder(connection).maxContentLength(maxContentLength)
        .propagateSettings(true)
        .build()))
        .frameLogger(logger)
        .connection(connection)
        .build();

    ApplicationProtocolNegotiationHandler clientAPNHandler = new ApplicationProtocolNegotiationHandler(ApplicationProtocolNames.HTTP_2) {
        @Override
        protected void configurePipeline(ChannelHandlerContext ctx, String protocol) {
            if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
                ChannelPipeline p = ctx.pipeline();
                p.addLast(connectionHandler);
                p.addLast(settingsHandler, responseHandler);
                return;
            }
            ctx.close();
            throw new IllegalStateException("Protocol: " + protocol + " not supported");
        }
    };

    return clientAPNHandler;

}
 
 类方法
 同包方法