From a6cd46e6d8d9f317c6de3256114510f11980530e Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Mon, 9 Mar 2020 22:25:52 +0300 Subject: [PATCH] [java] Sending auth headers to the grid if username and password are specified in the base URL. Fixes #8005 --- .../remote/http/netty/CreateNettyClient.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/java/client/src/org/openqa/selenium/remote/http/netty/CreateNettyClient.java b/java/client/src/org/openqa/selenium/remote/http/netty/CreateNettyClient.java index c660f685fa723..d017dd0dc2441 100644 --- a/java/client/src/org/openqa/selenium/remote/http/netty/CreateNettyClient.java +++ b/java/client/src/org/openqa/selenium/remote/http/netty/CreateNettyClient.java @@ -17,9 +17,11 @@ package org.openqa.selenium.remote.http.netty; -import static org.asynchttpclient.Dsl.asyncHttpClient; +import com.google.common.base.Strings; import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.DefaultAsyncHttpClientConfig; +import org.asynchttpclient.Dsl; import org.openqa.selenium.remote.http.ClientConfig; import java.util.Objects; @@ -31,6 +33,17 @@ class CreateNettyClient implements Function { public AsyncHttpClient apply(ClientConfig config) { Objects.requireNonNull(config, "Client config to use must be set."); - return asyncHttpClient(); + DefaultAsyncHttpClientConfig.Builder clientConfig = Dsl.config(); + + String info = config.baseUrl().getUserInfo(); + if (!Strings.isNullOrEmpty(info)) { + String[] parts = info.split(":", 2); + String user = parts[0]; + String pass = parts.length > 1 ? parts[1] : null; + + clientConfig.setRealm(Dsl.basicAuthRealm(user, pass).setUsePreemptiveAuth(true).build()); + } + + return Dsl.asyncHttpClient(clientConfig); } }