Skip to content

Commit

Permalink
[java] Sending auth headers to the grid if username and password are …
Browse files Browse the repository at this point in the history
…specified in the base URL. Fixes #8005
  • Loading branch information
barancev committed Mar 9, 2020
1 parent bdef858 commit a6cd46e
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +33,17 @@ class CreateNettyClient implements Function<ClientConfig, AsyncHttpClient> {
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);
}
}

0 comments on commit a6cd46e

Please sign in to comment.