Skip to content

Commit

Permalink
configurable protocol version for HTTP clients
Browse files Browse the repository at this point in the history
  • Loading branch information
jenschude committed Jan 21, 2025
1 parent 1775bc8 commit 7b557f3
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ public static HttpAsyncClientBuilder createClientBuilder(AsyncClientConnectionMa

public static PoolingAsyncClientConnectionManagerBuilder createConnectionManager(final int maxConnTotal,
final int maxConnPerRoute) {
return createConnectionManager(HttpVersionPolicy.NEGOTIATE, maxConnTotal, maxConnPerRoute);
}

public static PoolingAsyncClientConnectionManagerBuilder createConnectionManager(
final HttpVersionPolicy httpVersionPolicy, final int maxConnTotal, final int maxConnPerRoute) {
final TlsStrategy tlsStrategy = ClientTlsStrategyBuilder.create().useSystemProperties().build();
final TlsConfig tlsConfig = TlsConfig.copy(TlsConfig.DEFAULT)
.setVersionPolicy(HttpVersionPolicy.NEGOTIATE)
.build();
final TlsConfig tlsConfig = TlsConfig.copy(TlsConfig.DEFAULT).setVersionPolicy(httpVersionPolicy).build();
return PoolingAsyncClientConnectionManagerBuilder.create()
.setMaxConnPerRoute(maxConnPerRoute)
.setMaxConnTotal(maxConnTotal)
Expand All @@ -74,12 +77,27 @@ public CtApacheHttpClient() {
init();
}

public CtApacheHttpClient(final HttpVersionPolicy versionPolicy) {
super();
apacheHttpClient = createClientBuilder(
createConnectionManager(versionPolicy, MAX_REQUESTS, MAX_REQUESTS).build()).build();
init();
}

Check warning on line 85 in commercetools/commercetools-apachehttp-client/src/main/java/com/commercetools/http/apachehttp/CtApacheHttpClient.java

View check run for this annotation

Codecov / codecov/patch

commercetools/commercetools-apachehttp-client/src/main/java/com/commercetools/http/apachehttp/CtApacheHttpClient.java#L81-L85

Added lines #L81 - L85 were not covered by tests

public CtApacheHttpClient(final int maxConnTotal, final int maxConnPerRoute) {
super();
apacheHttpClient = createClientBuilder(createConnectionManager(maxConnTotal, maxConnPerRoute).build()).build();
init();
}

public CtApacheHttpClient(final HttpVersionPolicy versionPolicy, final int maxConnTotal,
final int maxConnPerRoute) {
super();
apacheHttpClient = createClientBuilder(
createConnectionManager(versionPolicy, maxConnTotal, maxConnPerRoute).build()).build();
init();
}

Check warning on line 99 in commercetools/commercetools-apachehttp-client/src/main/java/com/commercetools/http/apachehttp/CtApacheHttpClient.java

View check run for this annotation

Codecov / codecov/patch

commercetools/commercetools-apachehttp-client/src/main/java/com/commercetools/http/apachehttp/CtApacheHttpClient.java#L95-L99

Added lines #L95 - L99 were not covered by tests

public CtApacheHttpClient(final BuilderOptions options) {
super();
apacheHttpClient = options.plus(clientBuilder.get()).build();
Expand All @@ -94,6 +112,16 @@ public CtApacheHttpClient(final int maxConnTotal, final int maxConnPerRoute, fin
init();
}

public CtApacheHttpClient(final HttpVersionPolicy versionPolicy, final int maxConnTotal, final int maxConnPerRoute,
final BuilderOptions options) {
super();
apacheHttpClient = options
.plus(
createClientBuilder(createConnectionManager(versionPolicy, maxConnTotal, maxConnPerRoute).build()))
.build();
init();
}

Check warning on line 123 in commercetools/commercetools-apachehttp-client/src/main/java/com/commercetools/http/apachehttp/CtApacheHttpClient.java

View check run for this annotation

Codecov / codecov/patch

commercetools/commercetools-apachehttp-client/src/main/java/com/commercetools/http/apachehttp/CtApacheHttpClient.java#L117-L123

Added lines #L117 - L123 were not covered by tests

public CtApacheHttpClient(final Supplier<HttpAsyncClientBuilder> builderSupplier) {
super();
apacheHttpClient = builderSupplier.get().build();
Expand All @@ -112,6 +140,14 @@ public CtApacheHttpClient(final ExecutorService executor, final int maxConnTotal
init();
}

public CtApacheHttpClient(final ExecutorService executor, final HttpVersionPolicy versionPolicy,
final int maxConnTotal, final int maxConnPerRoute) {
super(executor);
apacheHttpClient = createClientBuilder(
createConnectionManager(versionPolicy, maxConnTotal, maxConnPerRoute).build()).build();
init();
}

Check warning on line 149 in commercetools/commercetools-apachehttp-client/src/main/java/com/commercetools/http/apachehttp/CtApacheHttpClient.java

View check run for this annotation

Codecov / codecov/patch

commercetools/commercetools-apachehttp-client/src/main/java/com/commercetools/http/apachehttp/CtApacheHttpClient.java#L145-L149

Added lines #L145 - L149 were not covered by tests

public CtApacheHttpClient(final ExecutorService executor, final BuilderOptions options) {
super(executor);
apacheHttpClient = options.plus(clientBuilder.get()).build();
Expand All @@ -127,6 +163,16 @@ public CtApacheHttpClient(final ExecutorService executor, final int maxConnTotal
init();
}

public CtApacheHttpClient(final ExecutorService executor, final HttpVersionPolicy versionPolicy,
final int maxConnTotal, final int maxConnPerRoute, final BuilderOptions options) {
super(executor);
apacheHttpClient = options
.plus(
createClientBuilder(createConnectionManager(versionPolicy, maxConnTotal, maxConnPerRoute).build()))
.build();
init();
}

Check warning on line 174 in commercetools/commercetools-apachehttp-client/src/main/java/com/commercetools/http/apachehttp/CtApacheHttpClient.java

View check run for this annotation

Codecov / codecov/patch

commercetools/commercetools-apachehttp-client/src/main/java/com/commercetools/http/apachehttp/CtApacheHttpClient.java#L168-L174

Added lines #L168 - L174 were not covered by tests

public CtApacheHttpClient(final ExecutorService executor, final Supplier<HttpAsyncClientBuilder> builderSupplier) {
super(executor);
apacheHttpClient = builderSupplier.get().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
package com.commercetools.http.asynchttp;

import io.vrap.rmf.base.client.SolutionInfo;
import io.vrap.rmf.base.client.VersionLoader;

import org.asynchttpclient.config.AsyncHttpClientConfigDefaults;

public class AsyncHttpClientSolutionInfo extends SolutionInfo {

public AsyncHttpClientSolutionInfo() {
setName("AsyncHttpAsyncClient");
setVersion(VersionLoader.loadVersionInfo("org.asynchttpclient", "async-http-client", "pom.properties",
"version", this.getClass().getClassLoader()));
setVersion(AsyncHttpClientConfigDefaults.AHC_VERSION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public CtJavaNetHttpClient() {
javaHttpClient = clientBuilder.get().build();
}

public CtJavaNetHttpClient(HttpClient.Version version) {
super();
javaHttpClient = clientBuilder.get().version(version).build();
}

Check warning on line 36 in commercetools/commercetools-javanet-client/src/main/java/com/commercetools/http/javanet/CtJavaNetHttpClient.java

View check run for this annotation

Codecov / codecov/patch

commercetools/commercetools-javanet-client/src/main/java/com/commercetools/http/javanet/CtJavaNetHttpClient.java#L34-L36

Added lines #L34 - L36 were not covered by tests

public CtJavaNetHttpClient(final BuilderOptions options) {
super();
javaHttpClient = options.plus(clientBuilder.get()).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import reactor.core.publisher.Mono;
import reactor.netty.ByteBufMono;
import reactor.netty.NettyOutbound;
import reactor.netty.http.HttpProtocol;
import reactor.netty.http.client.HttpClient;
import reactor.netty.http.client.HttpClientRequest;
import reactor.netty.http.client.HttpClientResponse;
Expand All @@ -41,12 +42,22 @@ public CtNettyHttpClient() {
this(MAX_REQUESTS);
}

public CtNettyHttpClient(int maxConnections) {
public CtNettyHttpClient(HttpProtocol protocol) {
this(protocol, MAX_REQUESTS);
}

Check warning on line 47 in commercetools/commercetools-reactornetty-client/src/main/java/com/commercetools/http/netty/CtNettyHttpClient.java

View check run for this annotation

Codecov / codecov/patch

commercetools/commercetools-reactornetty-client/src/main/java/com/commercetools/http/netty/CtNettyHttpClient.java#L46-L47

Added lines #L46 - L47 were not covered by tests

public CtNettyHttpClient(final int maxConnections) {
super();
this.nettyClient = createDefaultClient(maxConnections);
this.nettyClient.warmup();
}

public CtNettyHttpClient(final HttpProtocol protocol, final int maxConnections) {
super();
this.nettyClient = createDefaultClient(protocol, maxConnections);
this.nettyClient.warmup();
}

Check warning on line 59 in commercetools/commercetools-reactornetty-client/src/main/java/com/commercetools/http/netty/CtNettyHttpClient.java

View check run for this annotation

Codecov / codecov/patch

commercetools/commercetools-reactornetty-client/src/main/java/com/commercetools/http/netty/CtNettyHttpClient.java#L56-L59

Added lines #L56 - L59 were not covered by tests

public CtNettyHttpClient(final BuilderOptions options) {
this(MAX_REQUESTS, options);
}
Expand All @@ -73,6 +84,12 @@ public CtNettyHttpClient(final ExecutorService executor, final int maxConnection
this.nettyClient.warmup();
}

public CtNettyHttpClient(final ExecutorService executor, final HttpProtocol protocol, final int maxConnections) {
super(executor);
this.nettyClient = createDefaultClient(protocol, maxConnections);
this.nettyClient.warmup();
}

Check warning on line 91 in commercetools/commercetools-reactornetty-client/src/main/java/com/commercetools/http/netty/CtNettyHttpClient.java

View check run for this annotation

Codecov / codecov/patch

commercetools/commercetools-reactornetty-client/src/main/java/com/commercetools/http/netty/CtNettyHttpClient.java#L88-L91

Added lines #L88 - L91 were not covered by tests

public CtNettyHttpClient(final ExecutorService executor, final BuilderOptions options) {
this(executor, MAX_REQUESTS, options);
}
Expand All @@ -83,6 +100,13 @@ public CtNettyHttpClient(final ExecutorService executor, final int maxConnection
this.nettyClient.warmup();
}

public CtNettyHttpClient(final ExecutorService executor, final HttpProtocol protocol, final int maxConnections,
final BuilderOptions options) {
super(executor);
this.nettyClient = options.plus(createDefaultClient(protocol, maxConnections));
this.nettyClient.warmup();
}

Check warning on line 108 in commercetools/commercetools-reactornetty-client/src/main/java/com/commercetools/http/netty/CtNettyHttpClient.java

View check run for this annotation

Codecov / codecov/patch

commercetools/commercetools-reactornetty-client/src/main/java/com/commercetools/http/netty/CtNettyHttpClient.java#L105-L108

Added lines #L105 - L108 were not covered by tests

public CtNettyHttpClient(final ExecutorService executor, final Supplier<HttpClient> httpClientSupplier) {
super(executor);
this.nettyClient = httpClientSupplier.get();
Expand All @@ -97,6 +121,10 @@ public static HttpClient createDefaultClient(final int maxConnections) {
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000);
}

public static HttpClient createDefaultClient(final HttpProtocol httpProtocol, final int maxConnections) {
return createDefaultClient(maxConnections).protocol(httpProtocol);

Check warning on line 125 in commercetools/commercetools-reactornetty-client/src/main/java/com/commercetools/http/netty/CtNettyHttpClient.java

View check run for this annotation

Codecov / codecov/patch

commercetools/commercetools-reactornetty-client/src/main/java/com/commercetools/http/netty/CtNettyHttpClient.java#L125

Added line #L125 was not covered by tests
}

@Override
public CompletableFuture<ApiHttpResponse<byte[]>> execute(ApiHttpRequest request) {
final HttpMethod method = HttpMethod.valueOf(request.getMethod().name());
Expand Down

0 comments on commit 7b557f3

Please sign in to comment.