Add utility method to construct http client
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security.tls;
+import com.yahoo.security.tls.https.TlsAwareHttpClientBuilder;
+
+import java.net.http.HttpClient;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
@@ -48,6 +51,12 @@ public class TransportSecurityUtils {
.map(configFile -> new ReloadingTlsContext(configFile, getInsecureAuthorizationMode()));
}
+ public static HttpClient.Builder createHttpClientBuilder(String userAgent) {
+ return createTlsContext()
+ .map(tlsContext -> new TlsAwareHttpClientBuilder(tlsContext, userAgent))
+ .orElseGet(() -> new TlsAwareHttpClientBuilder(userAgent));
+ }
+
private static Optional<String> getEnvironmentVariable(String environmentVariable) {
return Optional.ofNullable(System.getenv(environmentVariable))
.filter(var -> !var.isEmpty());
