From c1a74e7870efa32ca8f7aebad23d20af3642852b Mon Sep 17 00:00:00 2001 From: titusfortner Date: Tue, 10 Oct 2023 16:21:29 -0500 Subject: [PATCH 1/2] [java] allow setting version in the Http Client Config --- .../selenium/remote/http/ClientConfig.java | 58 +++++++++++++++---- .../remote/http/jdk/JdkHttpClient.java | 6 ++ 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/java/src/org/openqa/selenium/remote/http/ClientConfig.java b/java/src/org/openqa/selenium/remote/http/ClientConfig.java index 26552eeb24327..b3ec058d3293b 100644 --- a/java/src/org/openqa/selenium/remote/http/ClientConfig.java +++ b/java/src/org/openqa/selenium/remote/http/ClientConfig.java @@ -23,6 +23,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.net.http.HttpClient; import java.time.Duration; import javax.net.ssl.SSLContext; import org.openqa.selenium.Credentials; @@ -38,8 +39,8 @@ public class ClientConfig { private final Filter filters; private final Proxy proxy; private final Credentials credentials; - private final SSLContext sslContext; + private HttpClient.Version version; protected ClientConfig( URI baseUri, @@ -48,7 +49,8 @@ protected ClientConfig( Filter filters, Proxy proxy, Credentials credentials, - SSLContext sslContext) { + SSLContext sslContext, + HttpClient.Version version) { this.baseUri = baseUri; this.connectionTimeout = Require.nonNegative("Connection timeout", connectionTimeout); this.readTimeout = Require.nonNegative("Read timeout", readTimeout); @@ -56,11 +58,19 @@ protected ClientConfig( this.proxy = proxy; this.credentials = credentials; this.sslContext = sslContext; + this.version = version; } public static ClientConfig defaultConfig() { return new ClientConfig( - null, Duration.ofSeconds(10), Duration.ofMinutes(3), DEFAULT_FILTER, null, null, null); + null, + Duration.ofSeconds(10), + Duration.ofMinutes(3), + DEFAULT_FILTER, + null, + null, + null, + null); } public ClientConfig baseUri(URI baseUri) { @@ -71,7 +81,8 @@ public ClientConfig baseUri(URI baseUri) { filters, proxy, credentials, - sslContext); + sslContext, + version); } public ClientConfig baseUrl(URL baseUrl) { @@ -102,7 +113,8 @@ public ClientConfig connectionTimeout(Duration timeout) { filters, proxy, credentials, - sslContext); + sslContext, + version); } public Duration connectionTimeout() { @@ -117,7 +129,8 @@ public ClientConfig readTimeout(Duration timeout) { filters, proxy, credentials, - sslContext); + sslContext, + version); } public Duration readTimeout() { @@ -133,7 +146,8 @@ public ClientConfig withFilter(Filter filter) { filter.andThen(DEFAULT_FILTER), proxy, credentials, - sslContext); + sslContext, + version); } public ClientConfig withRetries() { @@ -144,7 +158,8 @@ public ClientConfig withRetries() { filters.andThen(RETRY_FILTER), proxy, credentials, - sslContext); + sslContext, + version); } public Filter filter() { @@ -159,7 +174,8 @@ public ClientConfig proxy(Proxy proxy) { filters, Require.nonNull("Proxy", proxy), credentials, - sslContext); + sslContext, + version); } public Proxy proxy() { @@ -174,7 +190,8 @@ public ClientConfig authenticateAs(Credentials credentials) { filters, proxy, Require.nonNull("Credentials", credentials), - sslContext); + sslContext, + version); } public Credentials credentials() { @@ -189,13 +206,30 @@ public ClientConfig sslContext(SSLContext sslContext) { filters, proxy, credentials, - Require.nonNull("SSL Context", sslContext)); + Require.nonNull("SSL Context", sslContext), + version); } public SSLContext sslContext() { return sslContext; } + public ClientConfig version(HttpClient.Version version) { + return new ClientConfig( + baseUri, + connectionTimeout, + readTimeout, + filters, + proxy, + credentials, + sslContext, + Require.nonNull("Version", version)); + } + + public HttpClient.Version version() { + return version; + } + @Override public String toString() { return "ClientConfig{" @@ -213,6 +247,8 @@ public String toString() { + credentials + ", sslcontext=" + sslContext + + ", version=" + + version + '}'; } } diff --git a/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java b/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java index 019dd8ad06b70..6afff864b8d45 100644 --- a/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java +++ b/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java @@ -29,6 +29,7 @@ import java.net.SocketAddress; import java.net.URI; import java.net.URISyntaxException; +import java.net.http.HttpClient.Version; import java.net.http.HttpResponse.BodyHandler; import java.net.http.HttpResponse.BodyHandlers; import java.net.http.HttpTimeoutException; @@ -150,6 +151,11 @@ public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { builder.sslContext(sslContext); } + Version version = config.version(); + if (version != null) { + builder.version(version); + } + this.client = builder.build(); } From 64bcbd75d1a3b74145025573c8cbf276c5af77de Mon Sep 17 00:00:00 2001 From: titusfortner Date: Tue, 10 Oct 2023 16:53:07 -0500 Subject: [PATCH 2/2] [java] set client config version as string and convert in Jdk Client --- .../org/openqa/selenium/remote/http/ClientConfig.java | 9 ++++----- .../openqa/selenium/remote/http/jdk/JdkHttpClient.java | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/java/src/org/openqa/selenium/remote/http/ClientConfig.java b/java/src/org/openqa/selenium/remote/http/ClientConfig.java index b3ec058d3293b..b7ce769ad4651 100644 --- a/java/src/org/openqa/selenium/remote/http/ClientConfig.java +++ b/java/src/org/openqa/selenium/remote/http/ClientConfig.java @@ -23,7 +23,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.net.http.HttpClient; import java.time.Duration; import javax.net.ssl.SSLContext; import org.openqa.selenium.Credentials; @@ -40,7 +39,7 @@ public class ClientConfig { private final Proxy proxy; private final Credentials credentials; private final SSLContext sslContext; - private HttpClient.Version version; + private String version; protected ClientConfig( URI baseUri, @@ -50,7 +49,7 @@ protected ClientConfig( Proxy proxy, Credentials credentials, SSLContext sslContext, - HttpClient.Version version) { + String version) { this.baseUri = baseUri; this.connectionTimeout = Require.nonNegative("Connection timeout", connectionTimeout); this.readTimeout = Require.nonNegative("Read timeout", readTimeout); @@ -214,7 +213,7 @@ public SSLContext sslContext() { return sslContext; } - public ClientConfig version(HttpClient.Version version) { + public ClientConfig version(String version) { return new ClientConfig( baseUri, connectionTimeout, @@ -226,7 +225,7 @@ public ClientConfig version(HttpClient.Version version) { Require.nonNull("Version", version)); } - public HttpClient.Version version() { + public String version() { return version; } diff --git a/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java b/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java index 6afff864b8d45..86aed0a109c92 100644 --- a/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java +++ b/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java @@ -151,9 +151,9 @@ public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { builder.sslContext(sslContext); } - Version version = config.version(); + String version = config.version(); if (version != null) { - builder.version(version); + builder.version(Version.valueOf(version)); } this.client = builder.build();