Skip to content

Commit a6cd46e

Browse files
committed
[java] Sending auth headers to the grid if username and password are specified in the base URL. Fixes #8005
1 parent bdef858 commit a6cd46e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

java/client/src/org/openqa/selenium/remote/http/netty/CreateNettyClient.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
package org.openqa.selenium.remote.http.netty;
1919

20-
import static org.asynchttpclient.Dsl.asyncHttpClient;
20+
import com.google.common.base.Strings;
2121

2222
import org.asynchttpclient.AsyncHttpClient;
23+
import org.asynchttpclient.DefaultAsyncHttpClientConfig;
24+
import org.asynchttpclient.Dsl;
2325
import org.openqa.selenium.remote.http.ClientConfig;
2426

2527
import java.util.Objects;
@@ -31,6 +33,17 @@ class CreateNettyClient implements Function<ClientConfig, AsyncHttpClient> {
3133
public AsyncHttpClient apply(ClientConfig config) {
3234
Objects.requireNonNull(config, "Client config to use must be set.");
3335

34-
return asyncHttpClient();
36+
DefaultAsyncHttpClientConfig.Builder clientConfig = Dsl.config();
37+
38+
String info = config.baseUrl().getUserInfo();
39+
if (!Strings.isNullOrEmpty(info)) {
40+
String[] parts = info.split(":", 2);
41+
String user = parts[0];
42+
String pass = parts.length > 1 ? parts[1] : null;
43+
44+
clientConfig.setRealm(Dsl.basicAuthRealm(user, pass).setUsePreemptiveAuth(true).build());
45+
}
46+
47+
return Dsl.asyncHttpClient(clientConfig);
3548
}
3649
}

0 commit comments

Comments
 (0)