Skip to content
Permalink
Browse files
Upgraded HttpCore to version 5.2-beta1
  • Loading branch information
ok2c committed Mar 17, 2022
1 parent 5f9bc34 commit a3bbcc82ae9ad126ae1d0cb7b0839c288ed05c70
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 40 deletions.
@@ -765,7 +765,7 @@ public CloseableHttpAsyncClient build() {
}

final AsyncPushConsumerRegistry pushConsumerRegistry = new AsyncPushConsumerRegistry();
final IOEventHandlerFactory ioEventHandlerFactory = new H2AsyncClientEventHandlerFactory(
final IOEventHandlerFactory ioEventHandlerFactory = new H2AsyncClientProtocolStarter(
new DefaultHttpProcessor(new H2RequestContent(), new H2RequestTargetHost(), new H2RequestConnControl()),
(request, context) -> pushConsumerRegistry.get(request),
h2Config != null ? h2Config : H2Config.DEFAULT,
@@ -39,8 +39,8 @@
import org.apache.hc.core5.http2.config.H2Config;
import org.apache.hc.core5.http2.frame.FramePrinter;
import org.apache.hc.core5.http2.frame.RawFrame;
import org.apache.hc.core5.http2.impl.nio.ClientH2PrefaceHandler;
import org.apache.hc.core5.http2.impl.nio.ClientH2StreamMultiplexerFactory;
import org.apache.hc.core5.http2.impl.nio.H2OnlyClientProtocolNegotiator;
import org.apache.hc.core5.http2.impl.nio.H2StreamListener;
import org.apache.hc.core5.reactor.IOEventHandler;
import org.apache.hc.core5.reactor.IOEventHandlerFactory;
@@ -49,7 +49,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class H2AsyncClientEventHandlerFactory implements IOEventHandlerFactory {
class H2AsyncClientProtocolStarter implements IOEventHandlerFactory {

private static final Logger HEADER_LOG = LoggerFactory.getLogger("org.apache.hc.client5.http.headers");
private static final Logger FRAME_LOG = LoggerFactory.getLogger("org.apache.hc.client5.http2.frame");
@@ -61,7 +61,7 @@ class H2AsyncClientEventHandlerFactory implements IOEventHandlerFactory {
private final H2Config h2Config;
private final CharCodingConfig charCodingConfig;

H2AsyncClientEventHandlerFactory(
H2AsyncClientProtocolStarter(
final HttpProcessor httpProcessor,
final HandlerFactory<AsyncPushConsumer> exchangeHandlerFactory,
final H2Config h2Config,
@@ -163,15 +163,15 @@ public void onOutputFlowControl(final HttpConnection connection, final int strea
}

});
return new H2OnlyClientProtocolNegotiator(ioSession, http2StreamHandlerFactory, false);
return new ClientH2PrefaceHandler(ioSession, http2StreamHandlerFactory, false);
}
final ClientH2StreamMultiplexerFactory http2StreamHandlerFactory = new ClientH2StreamMultiplexerFactory(
httpProcessor,
exchangeHandlerFactory,
h2Config,
charCodingConfig,
null);
return new H2OnlyClientProtocolNegotiator(ioSession, http2StreamHandlerFactory, false);
return new ClientH2PrefaceHandler(ioSession, http2StreamHandlerFactory, false);
}

}
@@ -933,7 +933,7 @@ public CloseableHttpAsyncClient build() {
}
}
final AsyncPushConsumerRegistry pushConsumerRegistry = new AsyncPushConsumerRegistry();
final IOEventHandlerFactory ioEventHandlerFactory = new HttpAsyncClientEventHandlerFactory(
final IOEventHandlerFactory ioEventHandlerFactory = new HttpAsyncClientProtocolNegotiationStarter(
new DefaultHttpProcessor(new H2RequestContent(), new H2RequestTargetHost(), new H2RequestConnControl()),
(request, context) -> pushConsumerRegistry.get(request),
h2Config != null ? h2Config : H2Config.DEFAULT,
@@ -40,6 +40,7 @@
import org.apache.hc.core5.http.config.CharCodingConfig;
import org.apache.hc.core5.http.config.Http1Config;
import org.apache.hc.core5.http.impl.Http1StreamListener;
import org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler;
import org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexerFactory;
import org.apache.hc.core5.http.impl.nio.DefaultHttpRequestWriterFactory;
import org.apache.hc.core5.http.impl.nio.DefaultHttpResponseParserFactory;
@@ -54,17 +55,21 @@
import org.apache.hc.core5.http2.config.H2Config;
import org.apache.hc.core5.http2.frame.FramePrinter;
import org.apache.hc.core5.http2.frame.RawFrame;
import org.apache.hc.core5.http2.impl.nio.ClientH2PrefaceHandler;
import org.apache.hc.core5.http2.impl.nio.ClientH2StreamMultiplexerFactory;
import org.apache.hc.core5.http2.impl.nio.ClientHttpProtocolNegotiator;
import org.apache.hc.core5.http2.impl.nio.ClientH2UpgradeHandler;
import org.apache.hc.core5.http2.impl.nio.ClientHttp1UpgradeHandler;
import org.apache.hc.core5.http2.impl.nio.H2StreamListener;
import org.apache.hc.core5.http2.impl.nio.HttpProtocolNegotiator;
import org.apache.hc.core5.http2.ssl.ApplicationProtocol;
import org.apache.hc.core5.reactor.IOEventHandler;
import org.apache.hc.core5.reactor.IOEventHandlerFactory;
import org.apache.hc.core5.reactor.ProtocolIOSession;
import org.apache.hc.core5.util.Args;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class HttpAsyncClientEventHandlerFactory implements IOEventHandlerFactory {
class HttpAsyncClientProtocolNegotiationStarter implements IOEventHandlerFactory {

private static final Logger STREAM_LOG = LoggerFactory.getLogger(InternalHttpAsyncClient.class);
private static final Logger HEADER_LOG = LoggerFactory.getLogger("org.apache.hc.client5.http.headers");
@@ -81,7 +86,7 @@ class HttpAsyncClientEventHandlerFactory implements IOEventHandlerFactory {
private final NHttpMessageParserFactory<HttpResponse> http1ResponseParserFactory;
private final NHttpMessageWriterFactory<HttpRequest> http1RequestWriterFactory;

HttpAsyncClientEventHandlerFactory(
HttpAsyncClientProtocolNegotiationStarter(
final HttpProcessor httpProcessor,
final HandlerFactory<AsyncPushConsumer> exchangeHandlerFactory,
final H2Config h2Config,
@@ -100,13 +105,16 @@ class HttpAsyncClientEventHandlerFactory implements IOEventHandlerFactory {

@Override
public IOEventHandler createHandler(final ProtocolIOSession ioSession, final Object attachment) {
final ClientHttp1StreamDuplexerFactory http1StreamHandlerFactory;
final ClientH2StreamMultiplexerFactory http2StreamHandlerFactory;

if (STREAM_LOG.isDebugEnabled()
|| HEADER_LOG.isDebugEnabled()
|| FRAME_LOG.isDebugEnabled()
|| FRAME_PAYLOAD_LOG.isDebugEnabled()
|| FLOW_CTRL_LOG.isDebugEnabled()) {
final String id = ioSession.getId();
final ClientHttp1StreamDuplexerFactory http1StreamHandlerFactory = new ClientHttp1StreamDuplexerFactory(
http1StreamHandlerFactory = new ClientHttp1StreamDuplexerFactory(
httpProcessor,
h1Config,
charCodingConfig,
@@ -147,7 +155,7 @@ public void onExchangeComplete(final HttpConnection connection, final boolean ke
}

});
final ClientH2StreamMultiplexerFactory http2StreamHandlerFactory = new ClientH2StreamMultiplexerFactory(
http2StreamHandlerFactory = new ClientH2StreamMultiplexerFactory(
httpProcessor,
exchangeHandlerFactory,
h2Config,
@@ -231,31 +239,35 @@ public void onOutputFlowControl(final HttpConnection connection, final int strea
}

});
return new ClientHttpProtocolNegotiator(
ioSession,
http1StreamHandlerFactory,
http2StreamHandlerFactory,
attachment instanceof HttpVersionPolicy ? (HttpVersionPolicy) attachment : null);
} else {
http1StreamHandlerFactory = new ClientHttp1StreamDuplexerFactory(
httpProcessor,
h1Config,
charCodingConfig,
http1ConnectionReuseStrategy,
http1ResponseParserFactory,
http1RequestWriterFactory,
null);
http2StreamHandlerFactory = new ClientH2StreamMultiplexerFactory(
httpProcessor,
exchangeHandlerFactory,
h2Config,
charCodingConfig,
null);
}

ioSession.registerProtocol(ApplicationProtocol.HTTP_1_1.id, new ClientHttp1UpgradeHandler(http1StreamHandlerFactory));
ioSession.registerProtocol(ApplicationProtocol.HTTP_2.id, new ClientH2UpgradeHandler(http2StreamHandlerFactory));

final HttpVersionPolicy versionPolicy = attachment instanceof HttpVersionPolicy ? (HttpVersionPolicy) attachment : HttpVersionPolicy.NEGOTIATE;
switch (versionPolicy) {
case FORCE_HTTP_2:
return new ClientH2PrefaceHandler(ioSession, http2StreamHandlerFactory, false);
case FORCE_HTTP_1:
return new ClientHttp1IOEventHandler(http1StreamHandlerFactory.create(ioSession));
default:
return new HttpProtocolNegotiator(ioSession, null);
}
final ClientHttp1StreamDuplexerFactory http1StreamHandlerFactory = new ClientHttp1StreamDuplexerFactory(
httpProcessor,
h1Config,
charCodingConfig,
http1ConnectionReuseStrategy,
http1ResponseParserFactory,
http1RequestWriterFactory,
null);
final ClientH2StreamMultiplexerFactory http2StreamHandlerFactory = new ClientH2StreamMultiplexerFactory(
httpProcessor,
exchangeHandlerFactory,
h2Config,
charCodingConfig,
null);
return new ClientHttpProtocolNegotiator(
ioSession,
http1StreamHandlerFactory,
http2StreamHandlerFactory,
attachment instanceof HttpVersionPolicy ? (HttpVersionPolicy) attachment : null);
}

}
@@ -154,7 +154,7 @@ public static MinimalHttpAsyncClient createMinimal(
final AsyncClientConnectionManager connmgr) {
final AsyncPushConsumerRegistry pushConsumerRegistry = new AsyncPushConsumerRegistry();
return createMinimalHttpAsyncClientImpl(
new HttpAsyncClientEventHandlerFactory(
new HttpAsyncClientProtocolNegotiationStarter(
createMinimalProtocolProcessor(),
(request, context) -> pushConsumerRegistry.get(request),
h2Config,
@@ -182,7 +182,7 @@ public static MinimalHttpAsyncClient createMinimal(
final AsyncClientConnectionManager connmgr) {
final AsyncPushConsumerRegistry pushConsumerRegistry = new AsyncPushConsumerRegistry();
return createMinimalHttpAsyncClientImpl(
new HttpAsyncClientEventHandlerFactory(
new HttpAsyncClientProtocolNegotiationStarter(
createMinimalProtocolProcessor(),
(request, context) -> pushConsumerRegistry.get(request),
h2Config,
@@ -285,7 +285,7 @@ public static MinimalH2AsyncClient createHttp2Minimal(
final TlsStrategy tlsStrategy) {
final AsyncPushConsumerRegistry pushConsumerRegistry = new AsyncPushConsumerRegistry();
return createMinimalHttp2AsyncClientImpl(
new H2AsyncClientEventHandlerFactory(
new H2AsyncClientProtocolStarter(
createMinimalProtocolProcessor(),
(request, context) -> pushConsumerRegistry.get(request),
h2Config,
@@ -62,7 +62,7 @@
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<httpcore.version>5.2-alpha2</httpcore.version>
<httpcore.version>5.2-beta1</httpcore.version>
<log4j.version>2.17.0</log4j.version>
<commons-codec.version>1.15</commons-codec.version>
<conscrypt.version>2.5.2</conscrypt.version>

0 comments on commit a3bbcc8

Please sign in to comment.