use Http2ConnectionHandler instead of HttpToHttp2ConnectionHandler

This commit is contained in:
Jörg Prante 2017-06-03 16:27:55 +02:00
parent c46a247d5f
commit 2572b6cb7f
2 changed files with 9 additions and 6 deletions

View file

@ -1,6 +1,6 @@
group = org.xbib group = org.xbib
name = netty-http-client name = netty-http-client
version = 4.1.11.3 version = 4.1.11.4
netty.version = 4.1.11.Final netty.version = 4.1.11.Final
tcnative.version = 2.0.1.Final tcnative.version = 2.0.1.Final

View file

@ -26,9 +26,10 @@ import io.netty.handler.codec.http2.DefaultHttp2Connection;
import io.netty.handler.codec.http2.DelegatingDecompressorFrameListener; import io.netty.handler.codec.http2.DelegatingDecompressorFrameListener;
import io.netty.handler.codec.http2.Http2ClientUpgradeCodec; import io.netty.handler.codec.http2.Http2ClientUpgradeCodec;
import io.netty.handler.codec.http2.Http2Connection; import io.netty.handler.codec.http2.Http2Connection;
import io.netty.handler.codec.http2.Http2ConnectionHandler;
import io.netty.handler.codec.http2.Http2ConnectionHandlerBuilder;
import io.netty.handler.codec.http2.Http2FrameLogger; import io.netty.handler.codec.http2.Http2FrameLogger;
import io.netty.handler.codec.http2.HttpToHttp2ConnectionHandler; import io.netty.handler.codec.http2.Http2Settings;
import io.netty.handler.codec.http2.HttpToHttp2ConnectionHandlerBuilder;
import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LogLevel;
import io.netty.handler.ssl.ApplicationProtocolConfig; import io.netty.handler.ssl.ApplicationProtocolConfig;
import io.netty.handler.ssl.ApplicationProtocolNames; import io.netty.handler.ssl.ApplicationProtocolNames;
@ -134,7 +135,7 @@ public class HttpClientChannelInitializer extends ChannelInitializer<SocketChann
pipeline.addLast(http1connectionHandler); pipeline.addLast(http1connectionHandler);
configureHttp1Pipeline(pipeline, context, httpHandler); configureHttp1Pipeline(pipeline, context, httpHandler);
} else if (key.getVersion().majorVersion() == 2) { } else if (key.getVersion().majorVersion() == 2) {
HttpToHttp2ConnectionHandler http2connectionHandler = createHttp2ConnectionHandler(context); Http2ConnectionHandler http2connectionHandler = createHttp2ConnectionHandler(context);
// using the upgrade handler means mixed HTTP 1 and HTTP 2 on the same connection // using the upgrade handler means mixed HTTP 1 and HTTP 2 on the same connection
if (context.isInstallHttp2Upgrade()) { if (context.isInstallHttp2Upgrade()) {
HttpClientCodec http1connectionHandler = createHttp1ConnectionHandler(context); HttpClientCodec http1connectionHandler = createHttp1ConnectionHandler(context);
@ -220,11 +221,13 @@ public class HttpClientChannelInitializer extends ChannelInitializer<SocketChann
return new HttpClientCodec(context.getMaxInitialLineLength(), context.getMaxHeaderSize(), context.getMaxChunkSize()); return new HttpClientCodec(context.getMaxInitialLineLength(), context.getMaxHeaderSize(), context.getMaxChunkSize());
} }
static HttpToHttp2ConnectionHandler createHttp2ConnectionHandler(HttpClientChannelContext context) { static Http2ConnectionHandler createHttp2ConnectionHandler(HttpClientChannelContext context) {
final Http2Connection http2Connection = new DefaultHttp2Connection(false); final Http2Connection http2Connection = new DefaultHttp2Connection(false);
return new HttpToHttp2ConnectionHandlerBuilder() return new Http2ConnectionHandlerBuilder()
.connection(http2Connection) .connection(http2Connection)
.frameLogger(new Http2FrameLogger(LogLevel.TRACE, HttpClientChannelInitializer.class)) .frameLogger(new Http2FrameLogger(LogLevel.TRACE, HttpClientChannelInitializer.class))
.initialSettings(new Http2Settings())
.encoderEnforceMaxConcurrentStreams(true)
.frameListener(new DelegatingDecompressorFrameListener(http2Connection, .frameListener(new DelegatingDecompressorFrameListener(http2Connection,
new Http2EventHandler(http2Connection, context.getMaxContentLength(), false))) new Http2EventHandler(http2Connection, context.getMaxContentLength(), false)))
.build(); .build();