Upgraded HttpCore to version 5.2-beta1

This commit is contained in:
Oleg Kalnichevski 2022-03-17 17:18:12 +01:00
parent 5f9bc347ee
commit a3bbcc82ae
6 changed files with 52 additions and 40 deletions

View File

@ -765,7 +765,7 @@ public class H2AsyncClientBuilder {
}
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,

View File

@ -39,8 +39,8 @@ import org.apache.hc.core5.http.protocol.HttpProcessor;
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.apache.hc.core5.util.Args;
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,7 +163,7 @@ class H2AsyncClientEventHandlerFactory implements IOEventHandlerFactory {
}
});
return new H2OnlyClientProtocolNegotiator(ioSession, http2StreamHandlerFactory, false);
return new ClientH2PrefaceHandler(ioSession, http2StreamHandlerFactory, false);
}
final ClientH2StreamMultiplexerFactory http2StreamHandlerFactory = new ClientH2StreamMultiplexerFactory(
httpProcessor,
@ -171,7 +171,7 @@ class H2AsyncClientEventHandlerFactory implements IOEventHandlerFactory {
h2Config,
charCodingConfig,
null);
return new H2OnlyClientProtocolNegotiator(ioSession, http2StreamHandlerFactory, false);
return new ClientH2PrefaceHandler(ioSession, http2StreamHandlerFactory, false);
}
}

View File

@ -933,7 +933,7 @@ public class HttpAsyncClientBuilder {
}
}
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,

View File

@ -40,6 +40,7 @@ import org.apache.hc.core5.http.HttpResponse;
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,9 +55,13 @@ import org.apache.hc.core5.http2.HttpVersionPolicy;
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;
@ -64,7 +69,7 @@ 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 @@ class HttpAsyncClientEventHandlerFactory implements IOEventHandlerFactory {
}
});
final ClientH2StreamMultiplexerFactory http2StreamHandlerFactory = new ClientH2StreamMultiplexerFactory(
http2StreamHandlerFactory = new ClientH2StreamMultiplexerFactory(
httpProcessor,
exchangeHandlerFactory,
h2Config,
@ -231,31 +239,35 @@ class HttpAsyncClientEventHandlerFactory implements IOEventHandlerFactory {
}
});
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);
}
}

View File

@ -154,7 +154,7 @@ public final class HttpAsyncClients {
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 final class HttpAsyncClients {
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 final class HttpAsyncClients {
final TlsStrategy tlsStrategy) {
final AsyncPushConsumerRegistry pushConsumerRegistry = new AsyncPushConsumerRegistry();
return createMinimalHttp2AsyncClientImpl(
new H2AsyncClientEventHandlerFactory(
new H2AsyncClientProtocolStarter(
createMinimalProtocolProcessor(),
(request, context) -> pushConsumerRegistry.get(request),
h2Config,

View File

@ -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>