diff options
3 files changed, 16 insertions, 4 deletions
diff --git a/http-client/src/main/java/ai/vespa/hosted/client/AbstractHttpClient.java b/http-client/src/main/java/ai/vespa/hosted/client/AbstractHttpClient.java index 6a76ef65082..ed3fee101ed 100644 --- a/http-client/src/main/java/ai/vespa/hosted/client/AbstractHttpClient.java +++ b/http-client/src/main/java/ai/vespa/hosted/client/AbstractHttpClient.java @@ -147,10 +147,10 @@ public abstract class AbstractHttpClient implements HttpClient { private final Method method; private final HostStrategy hosts; + private final List<Supplier<Query>> dynamicQuery = new ArrayList<>(); + private final Map<String, List<String>> headers = new LinkedHashMap<>(); private HttpURL.Path path = Path.empty(); private HttpURL.Query query = Query.empty(); - private List<Supplier<Query>> dynamicQuery = new ArrayList<>(); - private Map<String, List<String>> headers = new LinkedHashMap<>(); private Supplier<HttpEntity> entity = () -> null; private RequestConfig config = HttpClient.defaultRequestConfig; private ResponseVerifier verifier = HttpClient.throwOnError; diff --git a/http-client/src/main/java/ai/vespa/hosted/client/HttpClient.java b/http-client/src/main/java/ai/vespa/hosted/client/HttpClient.java index 16a419bf324..eeb9c353f64 100644 --- a/http-client/src/main/java/ai/vespa/hosted/client/HttpClient.java +++ b/http-client/src/main/java/ai/vespa/hosted/client/HttpClient.java @@ -249,6 +249,11 @@ public interface HttpClient extends Closeable { @FunctionalInterface interface HostStrategy extends Iterable<URI> { + /** Attempts the given host once. */ + static HostStrategy of(URI host) { + return repeating(host, 1); + } + /** Attempts each request once against each listed host. */ static HostStrategy ordered(List<URI> hosts) { return List.copyOf(hosts)::iterator; diff --git a/http-utils/src/main/java/ai/vespa/util/http/hc5/DefaultHttpClientBuilder.java b/http-utils/src/main/java/ai/vespa/util/http/hc5/DefaultHttpClientBuilder.java index 8ad9d63cd1a..6adbcbf068c 100644 --- a/http-utils/src/main/java/ai/vespa/util/http/hc5/DefaultHttpClientBuilder.java +++ b/http-utils/src/main/java/ai/vespa/util/http/hc5/DefaultHttpClientBuilder.java @@ -4,11 +4,13 @@ import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; import org.apache.hc.client5.http.impl.classic.HttpClients; import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; +import org.apache.hc.client5.http.ssl.DefaultHostnameVerifier; import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder; import org.apache.hc.core5.http.ContentType; import org.apache.hc.core5.http.HttpHeaders; import org.apache.hc.core5.util.Timeout; +import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; import java.time.Duration; import java.util.Map; @@ -27,17 +29,22 @@ public class DefaultHttpClientBuilder { private DefaultHttpClientBuilder() { } public static HttpClientBuilder create(SSLContext sslContext, String userAgent) { - return create(() -> sslContext, userAgent); + return create(() -> sslContext, new DefaultHostnameVerifier(), userAgent); + } + + public static HttpClientBuilder create(SSLContext sslContext, HostnameVerifier verifier, String userAgent) { + return create(() -> sslContext, verifier, userAgent); } /** Creates an HTTP client builder with the given SSL context, and using the provided timeouts for requests where config is not overridden. */ - public static HttpClientBuilder create(Supplier<SSLContext> sslContext, String userAgent) { + public static HttpClientBuilder create(Supplier<SSLContext> sslContext, HostnameVerifier verifier, String userAgent) { return HttpClientBuilder.create() .setConnectionManager(PoolingHttpClientConnectionManagerBuilder .create() .setSSLSocketFactory(SSLConnectionSocketFactoryBuilder .create() .setSslContext(sslContext.get()) + .setHostnameVerifier(verifier) .build()) .build()) .setUserAgent(userAgent) |