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

[java] allow setting version in the Http Client Config #12919

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
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
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;
titusfortner marked this conversation as resolved.
Show resolved Hide resolved

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();
titusfortner marked this conversation as resolved.
Show resolved Hide resolved
if (version != null) {
builder.version(Version.valueOf(version));
}

this.client = builder.build();
}

Expand Down
Loading