From db517766c1f3f7c00e264905fde6334c4b6692f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Sautter?= Date: Thu, 29 Feb 2024 20:03:59 +0100 Subject: [PATCH] [java] use a static class for ProxySelector #13622 --- .../remote/http/jdk/JdkHttpClient.java | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java b/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java index c60b2892971c7..6c6b3a21bf506 100644 --- a/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java +++ b/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java @@ -135,24 +135,7 @@ protected PasswordAuthentication getPasswordAuthentication() { Proxy proxy = config.proxy(); if (proxy != null) { - ProxySelector proxySelector = - new ProxySelector() { - @Override - public List 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); } @@ -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 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 + } + } }