Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httpclient builder: tls strategy customization #355

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class ApacheHttpClient5TransportBuilder {
private Optional<Boolean> chunkedEnabled;
private JsonpMapper mapper;
private TransportOptions options;
private TlsStrategy tlsStrategy;

/**
* Creates a new builder instance and sets the hosts that the client will send requests to.
Expand Down Expand Up @@ -263,6 +264,16 @@ public ApacheHttpClient5TransportBuilder setChunkedEnabled(boolean chunkedEnable
return this;
}

/**
* Optional custom tls strategy to replace the default
*
* @param tlsStrategy custom tlsStrategy
*/
public ApacheHttpClient5TransportBuilder setTlsStrategy(TlsStrategy tlsStrategy) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think providing the way to customize the TlsStrategy would be beneficial (right now you could do that by providing own connectionManager instance, which is verbose). However we should do that iin a way to keep API concise, relying on XxxCallback hooks, for example RequestConfigCallback, HttpClientConfigCallback.

    public interface ClientTlsStrategyConfigCallback {
        ClientTlsStrategyBuilder customizeClientTlsStrategyClientTlsStrategyBuilder clientTlsStrategyBuilder);
    }

this.tlsStrategy = tlsStrategy;
return this;
}

/**
* Creates a new {@link RestClient} based on the provided configuration.
*/
Expand Down Expand Up @@ -338,7 +349,7 @@ private CloseableHttpAsyncClient createHttpClient() {
}

try {
final TlsStrategy tlsStrategy = ClientTlsStrategyBuilder.create()
final TlsStrategy tlsStrategy = this.tlsStrategy != null ? this.tlsStrategy : ClientTlsStrategyBuilder.create()
.setSslContext(SSLContext.getDefault())
// See https://issues.apache.org/jira/browse/HTTPCLIENT-2219
.setTlsDetailsFactory(new Factory<SSLEngine, TlsDetails>() {
Expand Down