From e90fe6c1b460b2dabdd1514b3e14e3299d1df7ca Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Thu, 25 Jul 2024 12:44:43 +0000 Subject: [PATCH] Allow setting JDKHttpClient connectionTimeout, readTimeout, version via system property Signed-off-by: Viet Nguyen Duc --- .../selenium/remote/http/ClientConfig.java | 8 +++++--- .../remote/internal/HttpClientTestBase.java | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/java/src/org/openqa/selenium/remote/http/ClientConfig.java b/java/src/org/openqa/selenium/remote/http/ClientConfig.java index 7c2af11628460..bfb0a95e3759f 100644 --- a/java/src/org/openqa/selenium/remote/http/ClientConfig.java +++ b/java/src/org/openqa/selenium/remote/http/ClientConfig.java @@ -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) { diff --git a/java/test/org/openqa/selenium/remote/internal/HttpClientTestBase.java b/java/test/org/openqa/selenium/remote/internal/HttpClientTestBase.java index fa3affc04a7aa..fc32e492db18d 100644 --- a/java/test/org/openqa/selenium/remote/internal/HttpClientTestBase.java +++ b/java/test/org/openqa/selenium/remote/internal/HttpClientTestBase.java @@ -203,6 +203,23 @@ void shouldAllowConfigurationOfRequestTimeout() { ClientConfig.defaultConfig().readTimeout(Duration.ofMillis(500)))); } + @Test + public void shouldAllowConfigurationFromSystemProperties() { + try { + System.setProperty("webdriver.httpclient.connectionTimeout", "60"); + System.setProperty("webdriver.httpclient.readTimeout", "300"); + System.setProperty("webdriver.httpclient.version", "HTTP_1_1"); + ClientConfig clientConfig = ClientConfig.defaultConfig(); + assertThat(clientConfig.connectionTimeout()).isEqualTo(Duration.ofSeconds(60)); + assertThat(clientConfig.readTimeout()).isEqualTo(Duration.ofSeconds(300)); + assertThat(clientConfig.version()).isEqualTo(HttpVersion.HTTP_1_1); + } finally { + System.clearProperty("webdriver.httpclient.connectionTimeout"); + System.clearProperty("webdriver.httpclient.readTimeout"); + System.clearProperty("webdriver.httpclient.version"); + } + } + private HttpResponse getResponseWithHeaders(final Multimap headers) { return executeWithinServer( new HttpRequest(GET, "/foo"),