@Override public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) throws Http2Exception { connection = connectionFactory.apply(this); if (useDecompressor) { decoder().frameListener(new DelegatingDecompressorFrameListener(decoder().connection(), connection)); } else { decoder().frameListener(connection); } connection.onSettingsRead(ctx, settings); if (addHandler != null) { addHandler.handle(connection); } }
@Override public void initChannel(SocketChannel ch) throws Exception { final Http2Connection connection = new DefaultHttp2Connection(false); connectionHandler = new HttpToHttp2ConnectionHandlerBuilder() .frameListener(new DelegatingDecompressorFrameListener( connection, new InboundHttp2ToHttpAdapterBuilder(connection) .maxContentLength(transportConfig.getPayload()) .propagateSettings(true) .build())) .connection(connection) .build(); responseHandler = new Http2ClientChannelHandler(); settingsHandler = new Http2SettingsHandler(ch.newPromise()); String protocol = transportConfig.getProviderInfo().getProtocolType(); if (RpcConstants.PROTOCOL_TYPE_H2.equals(protocol)) { configureSsl(ch); } else if (RpcConstants.PROTOCOL_TYPE_H2C.equals(protocol)) { if (!useH2cPriorKnowledge) { configureClearTextWithHttpUpgrade(ch); } else { configureClearTextWithPriorKnowledge(ch); } } }
@Override public void initChannel(SocketChannel ch) throws Exception { final Http2Connection connection = new DefaultHttp2Connection(false); connectionHandler = new HttpToHttp2ConnectionHandlerBuilder() .frameListener(new DelegatingDecompressorFrameListener( connection, new InboundHttp2ToHttpAdapterBuilder(connection) .maxContentLength(transportConfig.getPayload()) .propagateSettings(true) .build())) .connection(connection) .build(); responseHandler = new Http2ClientChannelHandler(); settingsHandler = new Http2SettingsHandler(ch.newPromise()); String protocol = transportConfig.getProviderInfo().getProtocolType(); if (RpcConstants.PROTOCOL_TYPE_H2.equals(protocol)) { configureSsl(ch); } else if (RpcConstants.PROTOCOL_TYPE_H2C.equals(protocol)) { if (!useH2cPriorKnowledge) { configureClearTextWithHttpUpgrade(ch); } else { configureClearTextWithPriorKnowledge(ch); } } }
@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 Http1ClientCodec sourceCodec = new Http1ClientCodec(); final HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler( sourceCodec, new Http2ClientUpgradeCodec(connHandler), 65536); p.addLast(sourceCodec, upgradeHandler, new UpgradeRequestHandler()); } }
@Override public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) throws Http2Exception { connection = connectionFactory.apply(this); if (useDecompressor) { decoder().frameListener(new DelegatingDecompressorFrameListener(decoder().connection(), connection)); } else { decoder().frameListener(connection); } connection.onSettingsRead(ctx, settings); if (addHandler != null) { addHandler.handle(connection); } }
@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()); if (sslCtx != null) { configureSsl(ch); } else { configureClearText(ch); } }
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { LOGGER.info("{} : handlerAdded", connectionInfo); Http2Connection connection = new DefaultHttp2Connection(true); ChannelHandler http2ConnHandler = new HttpToHttp2ConnectionHandlerBuilder() .frameListener(new DelegatingDecompressorFrameListener( connection, new InboundHttp2ToHttpAdapterBuilder(connection) .maxContentLength(master.config().getMaxContentLength()) .propagateSettings(true) .build())) .connection(connection) .frameLogger(new Http2FrameLogger(LogLevel.DEBUG)) .build(); ctx.pipeline() .addBefore(ctx.name(), null, http2ConnHandler) .addBefore(ctx.name(), null, new Http2Handler()); }
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { LOGGER.info("{} : handlerAdded", connectionInfo); Http2Connection connection = new DefaultHttp2Connection(false); ChannelHandler http2ConnHandler = new HttpToHttp2ConnectionHandlerBuilder() .frameListener(new DelegatingDecompressorFrameListener( connection, new InboundHttp2ToHttpAdapterBuilder(connection) .maxContentLength(master.config().getMaxContentLength()) .propagateSettings(true) .build())) .frameLogger(new Http2FrameLogger(LogLevel.DEBUG)) .connection(connection) .build(); ctx.pipeline() .addBefore(ctx.name(), null, http2ConnHandler) .addBefore(ctx.name(), null, new Http2Handler()); }
@Override public void initChannel(SocketChannel ch) throws Exception { final Http2Connection connection = new DefaultHttp2Connection(false); connectionHandler = new HttpToHttp2ConnectionHandlerBuilder() .frameListener(new DelegatingDecompressorFrameListener( connection, new InboundHttp2ToHttpAdapterBuilder(connection) .maxContentLength(transportConfig.getPayload()) .propagateSettings(true) .build())) .connection(connection) .build(); responseHandler = new Http2ClientChannelHandler(); settingsHandler = new Http2SettingsHandler(ch.newPromise()); String protocol = transportConfig.getProviderInfo().getProtocolType(); if (RpcConstants.PROTOCOL_TYPE_H2.equals(protocol)) { configureSsl(ch); } else if (RpcConstants.PROTOCOL_TYPE_H2C.equals(protocol)) { if (!useH2cPriorKnowledge) { configureClearTextWithHttpUpgrade(ch); } else { configureClearTextWithPriorKnowledge(ch); } } }
public HttpClientChannelInitializer(SenderConfiguration senderConfiguration, HttpRoute httpRoute, ConnectionManager connectionManager, ConnectionAvailabilityFuture connectionAvailabilityFuture) { this.httpTraceLogEnabled = senderConfiguration.isHttpTraceLogEnabled(); this.keepAliveConfig = senderConfiguration.getKeepAliveConfig(); this.proxyServerConfiguration = senderConfiguration.getProxyServerConfiguration(); this.http2ConnectionManager = connectionManager.getHttp2ConnectionManager(); this.senderConfiguration = senderConfiguration; this.httpRoute = httpRoute; this.sslConfig = senderConfiguration.getClientSSLConfig(); this.connectionAvailabilityFuture = connectionAvailabilityFuture; String httpVersion = senderConfiguration.getHttpVersion(); if (Float.valueOf(httpVersion) == Constants.HTTP_2_0) { http2 = true; } connection = new DefaultHttp2Connection(false); clientFrameListener = new ClientFrameListener(); Http2FrameListener frameListener = new DelegatingDecompressorFrameListener(connection, clientFrameListener); Http2ConnectionHandlerBuilder connectionHandlerBuilder = new Http2ConnectionHandlerBuilder(); if (httpTraceLogEnabled) { connectionHandlerBuilder.frameLogger(new FrameLogger(TRACE, Constants.TRACE_LOG_UPSTREAM)); } http2ConnectionHandler = connectionHandlerBuilder.connection(connection).frameListener(frameListener).build(); http2TargetHandler = new Http2TargetHandler(connection, http2ConnectionHandler.encoder()); if (sslConfig != null) { sslHandlerFactory = new SSLHandlerFactory(sslConfig); } }
.propagateSettings(false) .build(); DelegatingDecompressorFrameListener frameListener = new DelegatingDecompressorFrameListener( connection, inboundAdapter);
/** * For HTTP/2 we don't have anything as simple as the HttpClientCodec (at least, not in Netty * 5.0alpha 2), so we create the equivalent here. * * @return */ private NettyHttpToHttp2Handler makeHttp2ConnectionHandler() { // DefaultHttp2Connection is for client or server. False means "client". Http2Connection connection = new DefaultHttp2Connection(false); InboundHttp2ToHttpAdapter inboundAdapter = new InboundHttp2ToHttpAdapterBuilder(connection) .maxContentLength(this.requestPayloadSizeLimit) .propagateSettings(true) .build(); DelegatingDecompressorFrameListener frameListener = new DelegatingDecompressorFrameListener( connection, inboundAdapter); Http2Settings settings = new Http2Settings(); settings.initialWindowSize(NettyChannelContext.INITIAL_HTTP2_WINDOW_SIZE); NettyHttpToHttp2HandlerBuilder builder = new NettyHttpToHttp2HandlerBuilder() .connection(connection) .frameListener(frameListener) .initialSettings(settings); if (this.debugLogging) { Http2FrameLogger frameLogger = new Http2FrameLogger(LogLevel.INFO, NettyHttpClientRequestInitializer.class); builder.frameLogger(frameLogger); } NettyHttpToHttp2Handler connectionHandler = builder.build(); return connectionHandler; }
@Override public void initChannel(SocketChannel ch) throws Exception { final Http2Connection connection = new DefaultHttp2Connection(false); connectionHandler = new HttpToHttp2ConnectionHandlerBuilder() .frameListener(new DelegatingDecompressorFrameListener( connection, new InboundHttp2ToHttpAdapterBuilder(connection) .maxContentLength(maxContentLength) .propagateSettings(true) .build())) .frameLogger(logger) .connection(connection) .build(); responseHandler = new Http2ResponseHandler(); settingsHandler = new Http2SettingsHandler(ch.newPromise()); if (sslCtx != null) { configureSsl(ch); } else { configureClearText(ch); } }