Skip to content

Commit

Permalink
[java] use a static class for ProxySelector #13622
Browse files Browse the repository at this point in the history
  • Loading branch information
joerg1985 committed Feb 29, 2024
1 parent da62a40 commit db51776
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,7 @@ protected PasswordAuthentication getPasswordAuthentication() {

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);
}
return List.of();
}

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

Expand Down Expand Up @@ -488,4 +471,28 @@ public HttpClient createClient(ClientConfig config) {
return new JdkHttpClient(config);
}
}

private static class HttpProxySelector extends ProxySelector {
private final Proxy proxy;

public HttpProxySelector(Proxy proxy) {
this.proxy = proxy;
}

@Override
public List<Proxy> select(URI uri) {
if (proxy == null) {
return List.of();
}
if (uri.getScheme().toLowerCase().startsWith("http")) {
return List.of(proxy);
}
return List.of();
}

@Override
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
// Do nothing
}
}
}

0 comments on commit db51776

Please sign in to comment.