Skip to content

Commit 2280161

Browse files
authored
Allow setting JDKHttpClient connectionTimeout, readTimeout, version via system property (#14306)
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent 22d62bb commit 2280161

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

java/src/org/openqa/selenium/remote/http/ClientConfig.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ protected ClientConfig(
6363
public static ClientConfig defaultConfig() {
6464
return new ClientConfig(
6565
null,
66-
Duration.ofSeconds(10),
67-
Duration.ofMinutes(3),
66+
Duration.ofSeconds(
67+
Long.parseLong(System.getProperty("webdriver.httpclient.connectionTimeout", "10"))),
68+
Duration.ofSeconds(
69+
Long.parseLong(System.getProperty("webdriver.httpclient.readTimeout", "180"))),
6870
DEFAULT_FILTER,
6971
null,
7072
null,
7173
null,
72-
null);
74+
System.getProperty("webdriver.httpclient.version", null));
7375
}
7476

7577
public ClientConfig baseUri(URI baseUri) {

java/test/org/openqa/selenium/remote/internal/HttpClientTestBase.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,36 @@ void shouldAllowConfigurationOfRequestTimeout() {
203203
ClientConfig.defaultConfig().readTimeout(Duration.ofMillis(500))));
204204
}
205205

206+
@Test
207+
public void shouldAllowConfigurationFromSystemProperties() {
208+
delegate =
209+
req -> {
210+
try {
211+
Thread.sleep(1100);
212+
} catch (InterruptedException e) {
213+
throw new RuntimeException(e);
214+
}
215+
return new HttpResponse().setContent(Contents.utf8String("Connection timed out"));
216+
};
217+
try {
218+
System.setProperty("webdriver.httpclient.connectionTimeout", "1");
219+
System.setProperty("webdriver.httpclient.readTimeout", "300");
220+
System.setProperty("webdriver.httpclient.version", "HTTP_1_1");
221+
ClientConfig clientConfig = ClientConfig.defaultConfig();
222+
assertThat(clientConfig.connectionTimeout()).isEqualTo(Duration.ofSeconds(1));
223+
assertThat(clientConfig.readTimeout()).isEqualTo(Duration.ofSeconds(300));
224+
assertThat(clientConfig.version()).isEqualTo("HTTP_1_1");
225+
HttpClient client =
226+
createFactory().createClient(clientConfig.baseUri(URI.create(server.whereIs("/"))));
227+
HttpRequest request = new HttpRequest(GET, "/delayed");
228+
assertThatExceptionOfType(TimeoutException.class).isThrownBy(() -> client.execute(request));
229+
} finally {
230+
System.clearProperty("webdriver.httpclient.connectionTimeout");
231+
System.clearProperty("webdriver.httpclient.readTimeout");
232+
System.clearProperty("webdriver.httpclient.version");
233+
}
234+
}
235+
206236
private HttpResponse getResponseWithHeaders(final Multimap<String, String> headers) {
207237
return executeWithinServer(
208238
new HttpRequest(GET, "/foo"),

0 commit comments

Comments
 (0)