Skip to content

Commit

Permalink
[java] allow setting version in the Http Client Config (#12919)
Browse files Browse the repository at this point in the history
* [java] allow setting version in the Http Client Config

* [java] set client config version as string and convert in Jdk Client
  • Loading branch information
titusfortner authored Oct 11, 2023
1 parent 27c7fdb commit dd00a0a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 11 deletions.
57 changes: 46 additions & 11 deletions java/src/org/openqa/selenium/remote/http/ClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public class ClientConfig {
private final Filter filters;
private final Proxy proxy;
private final Credentials credentials;

private final SSLContext sslContext;
private String version;

protected ClientConfig(
URI baseUri,
Expand All @@ -48,19 +48,28 @@ protected ClientConfig(
Filter filters,
Proxy proxy,
Credentials credentials,
SSLContext sslContext) {
SSLContext sslContext,
String version) {
this.baseUri = baseUri;
this.connectionTimeout = Require.nonNegative("Connection timeout", connectionTimeout);
this.readTimeout = Require.nonNegative("Read timeout", readTimeout);
this.filters = Require.nonNull("Filters", filters);
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) {
Expand All @@ -71,7 +80,8 @@ public ClientConfig baseUri(URI baseUri) {
filters,
proxy,
credentials,
sslContext);
sslContext,
version);
}

public ClientConfig baseUrl(URL baseUrl) {
Expand Down Expand Up @@ -102,7 +112,8 @@ public ClientConfig connectionTimeout(Duration timeout) {
filters,
proxy,
credentials,
sslContext);
sslContext,
version);
}

public Duration connectionTimeout() {
Expand All @@ -117,7 +128,8 @@ public ClientConfig readTimeout(Duration timeout) {
filters,
proxy,
credentials,
sslContext);
sslContext,
version);
}

public Duration readTimeout() {
Expand All @@ -133,7 +145,8 @@ public ClientConfig withFilter(Filter filter) {
filter.andThen(DEFAULT_FILTER),
proxy,
credentials,
sslContext);
sslContext,
version);
}

public ClientConfig withRetries() {
Expand All @@ -144,7 +157,8 @@ public ClientConfig withRetries() {
filters.andThen(RETRY_FILTER),
proxy,
credentials,
sslContext);
sslContext,
version);
}

public Filter filter() {
Expand All @@ -159,7 +173,8 @@ public ClientConfig proxy(Proxy proxy) {
filters,
Require.nonNull("Proxy", proxy),
credentials,
sslContext);
sslContext,
version);
}

public Proxy proxy() {
Expand All @@ -174,7 +189,8 @@ public ClientConfig authenticateAs(Credentials credentials) {
filters,
proxy,
Require.nonNull("Credentials", credentials),
sslContext);
sslContext,
version);
}

public Credentials credentials() {
Expand All @@ -189,13 +205,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(String version) {
return new ClientConfig(
baseUri,
connectionTimeout,
readTimeout,
filters,
proxy,
credentials,
sslContext,
Require.nonNull("Version", version));
}

public String version() {
return version;
}

@Override
public String toString() {
return "ClientConfig{"
Expand All @@ -213,6 +246,8 @@ public String toString() {
+ credentials
+ ", sslcontext="
+ sslContext
+ ", version="
+ version
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -150,6 +151,11 @@ public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
builder.sslContext(sslContext);
}

String version = config.version();
if (version != null) {
builder.version(Version.valueOf(version));
}

this.client = builder.build();
}

Expand Down

0 comments on commit dd00a0a

Please sign in to comment.