Skip to content

Commit db51776

Browse files
committed
[java] use a static class for ProxySelector #13622
1 parent da62a40 commit db51776

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -135,24 +135,7 @@ protected PasswordAuthentication getPasswordAuthentication() {
135135

136136
Proxy proxy = config.proxy();
137137
if (proxy != null) {
138-
ProxySelector proxySelector =
139-
new ProxySelector() {
140-
@Override
141-
public List<Proxy> select(URI uri) {
142-
if (proxy == null) {
143-
return List.of();
144-
}
145-
if (uri.getScheme().toLowerCase().startsWith("http")) {
146-
return List.of(proxy);
147-
}
148-
return List.of();
149-
}
150-
151-
@Override
152-
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
153-
// Do nothing
154-
}
155-
};
138+
ProxySelector proxySelector = new HttpProxySelector(proxy);
156139
builder = builder.proxy(proxySelector);
157140
}
158141

@@ -488,4 +471,28 @@ public HttpClient createClient(ClientConfig config) {
488471
return new JdkHttpClient(config);
489472
}
490473
}
474+
475+
private static class HttpProxySelector extends ProxySelector {
476+
private final Proxy proxy;
477+
478+
public HttpProxySelector(Proxy proxy) {
479+
this.proxy = proxy;
480+
}
481+
482+
@Override
483+
public List<Proxy> select(URI uri) {
484+
if (proxy == null) {
485+
return List.of();
486+
}
487+
if (uri.getScheme().toLowerCase().startsWith("http")) {
488+
return List.of(proxy);
489+
}
490+
return List.of();
491+
}
492+
493+
@Override
494+
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
495+
// Do nothing
496+
}
497+
}
491498
}

0 commit comments

Comments
 (0)