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

Allow setting JDKHttpClient connectionTimeout, readTimeout, version via system property #14306

Merged
merged 4 commits into from
Jul 29, 2024
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
8 changes: 5 additions & 3 deletions java/src/org/openqa/selenium/remote/http/ClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ protected ClientConfig(
public static ClientConfig defaultConfig() {
return new ClientConfig(
null,
Duration.ofSeconds(10),
Duration.ofMinutes(3),
Duration.ofSeconds(
Long.parseLong(System.getProperty("webdriver.httpclient.connectionTimeout", "10"))),
Duration.ofSeconds(
Long.parseLong(System.getProperty("webdriver.httpclient.readTimeout", "180"))),
DEFAULT_FILTER,
null,
null,
null,
null);
System.getProperty("webdriver.httpclient.version", null));
}

public ClientConfig baseUri(URI baseUri) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,36 @@ void shouldAllowConfigurationOfRequestTimeout() {
ClientConfig.defaultConfig().readTimeout(Duration.ofMillis(500))));
}

@Test
public void shouldAllowConfigurationFromSystemProperties() {
delegate =
req -> {
try {
Thread.sleep(1100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return new HttpResponse().setContent(Contents.utf8String("Connection timed out"));
};
try {
System.setProperty("webdriver.httpclient.connectionTimeout", "1");
System.setProperty("webdriver.httpclient.readTimeout", "300");
System.setProperty("webdriver.httpclient.version", "HTTP_1_1");
ClientConfig clientConfig = ClientConfig.defaultConfig();
assertThat(clientConfig.connectionTimeout()).isEqualTo(Duration.ofSeconds(1));
assertThat(clientConfig.readTimeout()).isEqualTo(Duration.ofSeconds(300));
assertThat(clientConfig.version()).isEqualTo("HTTP_1_1");
HttpClient client =
createFactory().createClient(clientConfig.baseUri(URI.create(server.whereIs("/"))));
HttpRequest request = new HttpRequest(GET, "/delayed");
assertThatExceptionOfType(TimeoutException.class).isThrownBy(() -> client.execute(request));
} finally {
System.clearProperty("webdriver.httpclient.connectionTimeout");
System.clearProperty("webdriver.httpclient.readTimeout");
System.clearProperty("webdriver.httpclient.version");
}
}

private HttpResponse getResponseWithHeaders(final Multimap<String, String> headers) {
return executeWithinServer(
new HttpRequest(GET, "/foo"),
Expand Down
Loading