Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.Authenticator;
import java.net.InetSocketAddress;
import java.net.PasswordAuthentication;
import java.net.ProtocolException;
import java.net.Proxy;
Expand All @@ -45,6 +46,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -123,28 +125,34 @@ protected PasswordAuthentication getPasswordAuthentication() {
builder = builder.authenticator(authenticator);
}

Proxy proxy = config.proxy();
if (proxy != null) {
ProxySelector proxySelector =
new ProxySelector() {
@Override
public List<Proxy> select(URI uri) {
if (proxy == null) {
return List.of();
}
if (uri.getScheme().toLowerCase().startsWith("http")) {
return List.of(proxy);
}
String proxyHost = System.getProperty("http.proxyHost");
String proxyPort = System.getProperty("http.proxyPort");

Proxy proxy =
(proxyHost != null && proxyPort != null)
? new Proxy(
Proxy.Type.HTTP, new InetSocketAddress(proxyHost, Integer.parseInt(proxyPort)))
: config.proxy();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pujagani I think an explicit set config.proxy() should beat the global system property?
And is it needed to implement this, this is just the standard behaviour of the HttpClient and should work out of the box?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS: I use java.net.useSystemProxies=true to pickup the system settings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same thought process before I made the code change. I tried using https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/doc-files/net-properties.html, and also tried digging in the HttpClient client at the part where the proxy is set, it didn't seem to use the standard system properties.


ProxySelector proxySelector =
new ProxySelector() {
@Override
public List<Proxy> select(URI uri) {
if (proxy == null) {
return List.of();
}

@Override
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
// Do nothing
if (uri.getScheme().toLowerCase().startsWith("http")) {
return List.of(proxy);
}
};
builder = builder.proxy(proxySelector);
}
return List.of();
}

@Override
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
// Do nothing
}
};
builder = builder.proxy(proxySelector);

SSLContext sslContext = config.sslContext();
if (sslContext != null) {
Expand Down