diff --git a/demos/embedded/src/test/java/org/eclipse/jetty/demos/ProxyServerTest.java b/demos/embedded/src/test/java/org/eclipse/jetty/demos/ProxyServerTest.java index 1ea27c25a8e..4598ab768b6 100644 --- a/demos/embedded/src/test/java/org/eclipse/jetty/demos/ProxyServerTest.java +++ b/demos/embedded/src/test/java/org/eclipse/jetty/demos/ProxyServerTest.java @@ -40,7 +40,7 @@ public class ProxyServerTest extends AbstractEmbeddedTest server.start(); URI uri = server.getURI(); - client.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", uri.getPort())); + client.getProxyConfiguration().addProxy(new HttpProxy("localhost", uri.getPort())); } @AfterEach diff --git a/documentation/jetty-documentation/src/main/java/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java b/documentation/jetty-documentation/src/main/java/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java index 91ddace1291..4b71a9b6978 100644 --- a/documentation/jetty-documentation/src/main/java/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java +++ b/documentation/jetty-documentation/src/main/java/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java @@ -659,7 +659,7 @@ public class HTTPClientDocs // Add the new proxy to the list of proxies already registered. ProxyConfiguration proxyConfig = httpClient.getProxyConfiguration(); - proxyConfig.getProxies().add(proxy); + proxyConfig.addProxy(proxy); ContentResponse response = httpClient.GET("http://domain.com/path"); // end::proxy[] @@ -684,7 +684,7 @@ public class HTTPClientDocs // Proxy configuration. ProxyConfiguration proxyConfig = httpClient.getProxyConfiguration(); HttpProxy proxy = new HttpProxy("proxy.net", 8080); - proxyConfig.getProxies().add(proxy); + proxyConfig.addProxy(proxy); ContentResponse response = httpClient.newRequest(serverURI).send(); // end::proxyAuthentication[] diff --git a/documentation/jetty-documentation/src/main/java/org/eclipse/jetty/docs/programming/client/websocket/WebSocketClientDocs.java b/documentation/jetty-documentation/src/main/java/org/eclipse/jetty/docs/programming/client/websocket/WebSocketClientDocs.java index dce2373692b..85835c4461f 100644 --- a/documentation/jetty-documentation/src/main/java/org/eclipse/jetty/docs/programming/client/websocket/WebSocketClientDocs.java +++ b/documentation/jetty-documentation/src/main/java/org/eclipse/jetty/docs/programming/client/websocket/WebSocketClientDocs.java @@ -54,7 +54,7 @@ public class WebSocketClientDocs // Instantiate and configure HttpClient. HttpClient httpClient = new HttpClient(); // For example, configure a proxy. - httpClient.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", 8888)); + httpClient.getProxyConfiguration().addProxy(new HttpProxy("localhost", 8888)); // Instantiate WebSocketClient, passing HttpClient to the constructor. WebSocketClient webSocketClient = new WebSocketClient(httpClient); diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/ProxyConfiguration.java b/jetty-client/src/main/java/org/eclipse/jetty/client/ProxyConfiguration.java index c826ced88f2..e3922c4fd43 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/ProxyConfiguration.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/ProxyConfiguration.java @@ -14,13 +14,14 @@ package org.eclipse.jetty.client; import java.net.URI; -import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Set; import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.io.ClientConnectionFactory; +import org.eclipse.jetty.util.BlockingArrayQueue; import org.eclipse.jetty.util.HostPort; import org.eclipse.jetty.util.ssl.SslContextFactory; @@ -30,23 +31,50 @@ import org.eclipse.jetty.util.ssl.SslContextFactory; * Applications add subclasses of {@link Proxy} to this configuration via: *
  * ProxyConfiguration proxyConfig = httpClient.getProxyConfiguration();
- * proxyConfig.getProxies().add(new HttpProxy(proxyHost, 8080));
+ * proxyConfig.addProxy(new HttpProxy(proxyHost, 8080));
  * 
* * @see HttpClient#getProxyConfiguration() */ public class ProxyConfiguration { - private final List proxies = new ArrayList<>(); + private final List proxies = new BlockingArrayQueue<>(); + /** + * @deprecated use {@link #addProxy(Proxy)} and {@link #removeProxy(Proxy)} instead + * @return the forward proxies to use + */ + @Deprecated(forRemoval = true) public List getProxies() { return proxies; } + /** + * Adds a proxy. + * + * @param proxy a proxy + * @throws NullPointerException if {@code proxy} is null + */ + public void addProxy(Proxy proxy) + { + proxies.add(Objects.requireNonNull(proxy)); + } + + /** + * Removes a proxy. + * + * @param proxy a proxy + * @return true if a match is found + */ + public boolean removeProxy(Proxy proxy) + { + return proxies.remove(proxy); + } + public Proxy match(Origin origin) { - for (Proxy proxy : getProxies()) + for (Proxy proxy : proxies) { if (proxy.matches(origin)) return proxy; diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientCustomProxyTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientCustomProxyTest.java index 6cb964dcd83..6e0e36a99af 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientCustomProxyTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientCustomProxyTest.java @@ -98,7 +98,7 @@ public class HttpClientCustomProxyTest // Setup the custom proxy int proxyPort = connector.getLocalPort(); int serverPort = proxyPort + 1; // Any port will do for these tests - just not the same as the proxy - client.getProxyConfiguration().getProxies().add(new CAFEBABEProxy(new Origin.Address("localhost", proxyPort), false)); + client.getProxyConfiguration().addProxy(new CAFEBABEProxy(new Origin.Address("localhost", proxyPort), false)); ContentResponse response = client.newRequest(serverHost, serverPort) .timeout(5, TimeUnit.SECONDS) diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientProxyProtocolTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientProxyProtocolTest.java index 9c882e73948..1ecf680d806 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientProxyProtocolTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientProxyProtocolTest.java @@ -231,7 +231,7 @@ public class HttpClientProxyProtocolTest int proxyPort = connector.getLocalPort(); int serverPort = proxyPort + 1; // Any port will do. - client.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", proxyPort)); + client.getProxyConfiguration().addProxy(new HttpProxy("localhost", proxyPort)); // We are simulating to be a HttpClient inside a proxy. // The server is configured with the PROXY protocol to know the socket address of clients. diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientProxyTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientProxyTest.java index 3c158d6888c..c7b00eeba15 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientProxyTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientProxyTest.java @@ -60,7 +60,7 @@ public class HttpClientProxyTest extends AbstractHttpClientServerTest int proxyPort = connector.getLocalPort(); int serverPort = proxyPort + 1; // Any port will do for these tests - just not the same as the proxy - client.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", proxyPort)); + client.getProxyConfiguration().addProxy(new HttpProxy("localhost", proxyPort)); ContentResponse response = client.newRequest(serverHost, serverPort) .scheme(scenario.getScheme()) @@ -108,7 +108,7 @@ public class HttpClientProxyTest extends AbstractHttpClientServerTest String proxyHost = "localhost"; int proxyPort = connector.getLocalPort(); int serverPort = proxyPort + 1; // Any port will do for these tests - just not the same as the proxy - client.getProxyConfiguration().getProxies().add(new HttpProxy(proxyHost, proxyPort)); + client.getProxyConfiguration().addProxy(new HttpProxy(proxyHost, proxyPort)); ContentResponse response1 = client.newRequest(serverHost, serverPort) .scheme(scenario.getScheme()) @@ -202,7 +202,7 @@ public class HttpClientProxyTest extends AbstractHttpClientServerTest }); int proxyPort = connector.getLocalPort(); - client.getProxyConfiguration().getProxies().add(new HttpProxy(proxyHost, proxyPort)); + client.getProxyConfiguration().addProxy(new HttpProxy(proxyHost, proxyPort)); ContentResponse response1 = client.newRequest(serverHost, serverPort) .scheme(scenario.getScheme()) @@ -290,7 +290,7 @@ public class HttpClientProxyTest extends AbstractHttpClientServerTest client.getAuthenticationStore().addAuthentication(new BasicAuthentication(proxyURI, proxyRealm, "proxyUser", "proxyPassword")); URI serverURI = URI.create(scenario.getScheme() + "://" + serverHost + ":" + serverPort); client.getAuthenticationStore().addAuthentication(new BasicAuthentication(serverURI, serverRealm, "serverUser", "serverPassword")); - client.getProxyConfiguration().getProxies().add(new HttpProxy(proxyHost, proxyPort)); + client.getProxyConfiguration().addProxy(new HttpProxy(proxyHost, proxyPort)); final AtomicInteger requests = new AtomicInteger(); client.getRequestListeners().add(new Request.Listener.Adapter() { @@ -361,7 +361,7 @@ public class HttpClientProxyTest extends AbstractHttpClientServerTest int serverPort = proxyPort + 1; URI proxyURI = URI.create(scenario.getScheme() + "://" + proxyHost + ":" + proxyPort); client.getAuthenticationStore().addAuthentication(new BasicAuthentication(proxyURI, proxyRealm, "proxyUser", "proxyPassword")); - client.getProxyConfiguration().getProxies().add(new HttpProxy(proxyHost, proxyPort)); + client.getProxyConfiguration().addProxy(new HttpProxy(proxyHost, proxyPort)); final AtomicInteger requests = new AtomicInteger(); client.getRequestListeners().add(new Request.Listener.Adapter() { diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/Socks4ProxyTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/Socks4ProxyTest.java index 97770100b26..898836eb115 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/Socks4ProxyTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/Socks4ProxyTest.java @@ -77,7 +77,7 @@ public class Socks4ProxyTest public void testSocks4Proxy() throws Exception { int proxyPort = proxy.socket().getLocalPort(); - client.getProxyConfiguration().getProxies().add(new Socks4Proxy("localhost", proxyPort)); + client.getProxyConfiguration().addProxy(new Socks4Proxy("localhost", proxyPort)); CountDownLatch latch = new CountDownLatch(1); @@ -139,7 +139,7 @@ public class Socks4ProxyTest public void testSocks4ProxyWithSplitResponse() throws Exception { int proxyPort = proxy.socket().getLocalPort(); - client.getProxyConfiguration().getProxies().add(new Socks4Proxy("localhost", proxyPort)); + client.getProxyConfiguration().addProxy(new Socks4Proxy("localhost", proxyPort)); CountDownLatch latch = new CountDownLatch(1); @@ -215,7 +215,7 @@ public class Socks4ProxyTest // The hostname must be that of the server, not of the proxy. ssl.setHostnameVerifier((hostname, session) -> serverHost.equals(hostname)); }); - client.getProxyConfiguration().getProxies().add(new Socks4Proxy(proxyHost, proxyPort)); + client.getProxyConfiguration().addProxy(new Socks4Proxy(proxyHost, proxyPort)); CountDownLatch latch = new CountDownLatch(1); client.newRequest(serverHost, serverPort) @@ -283,7 +283,7 @@ public class Socks4ProxyTest { String proxyHost = "localhost"; int proxyPort = proxy.socket().getLocalPort(); - client.getProxyConfiguration().getProxies().add(new Socks4Proxy(proxyHost, proxyPort)); + client.getProxyConfiguration().addProxy(new Socks4Proxy(proxyHost, proxyPort)); long timeout = 1000; Request request = client.newRequest("localhost", proxyPort + 1) @@ -305,7 +305,7 @@ public class Socks4ProxyTest { String proxyHost = "localhost"; int proxyPort = proxy.socket().getLocalPort(); - client.getProxyConfiguration().getProxies().add(new Socks4Proxy(proxyHost, proxyPort)); + client.getProxyConfiguration().addProxy(new Socks4Proxy(proxyHost, proxyPort)); long idleTimeout = 1000; client.setIdleTimeout(idleTimeout); @@ -327,7 +327,7 @@ public class Socks4ProxyTest { String proxyHost = "localhost"; int proxyPort = proxy.socket().getLocalPort(); - client.getProxyConfiguration().getProxies().add(new Socks4Proxy(proxyHost, proxyPort)); + client.getProxyConfiguration().addProxy(new Socks4Proxy(proxyHost, proxyPort)); Request request = client.newRequest("localhost", proxyPort + 1); FutureResponseListener listener = new FutureResponseListener(request); diff --git a/jetty-http2/http2-http-client-transport/src/test/java/org/eclipse/jetty/http2/client/http/HttpClientTransportOverHTTP2Test.java b/jetty-http2/http2-http-client-transport/src/test/java/org/eclipse/jetty/http2/client/http/HttpClientTransportOverHTTP2Test.java index e8b6d01c9fe..dea91ece9fb 100644 --- a/jetty-http2/http2-http-client-transport/src/test/java/org/eclipse/jetty/http2/client/http/HttpClientTransportOverHTTP2Test.java +++ b/jetty-http2/http2-http-client-transport/src/test/java/org/eclipse/jetty/http2/client/http/HttpClientTransportOverHTTP2Test.java @@ -345,7 +345,7 @@ public class HttpClientTransportOverHTTP2Test extends AbstractTest }); int proxyPort = connector.getLocalPort(); - client.getProxyConfiguration().getProxies().add(new HttpProxy(new Origin.Address("localhost", proxyPort), false, new Origin.Protocol(List.of("h2c"), false))); + client.getProxyConfiguration().addProxy(new HttpProxy(new Origin.Address("localhost", proxyPort), false, new Origin.Protocol(List.of("h2c"), false))); int serverPort = proxyPort + 1; // Any port will do, just not the same as the proxy. ContentResponse response = client.newRequest("localhost", serverPort) diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncMiddleManServletTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncMiddleManServletTest.java index 554f7a12aba..5e7b212ed34 100644 --- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncMiddleManServletTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncMiddleManServletTest.java @@ -152,7 +152,7 @@ public class AsyncMiddleManServletTest clientPool.setName("client"); client = new HttpClient(); client.setExecutor(clientPool); - client.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", proxyConnector.getLocalPort())); + client.getProxyConfiguration().addProxy(new HttpProxy("localhost", proxyConnector.getLocalPort())); client.start(); } diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ForwardProxyServerTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ForwardProxyServerTest.java index 5cc07742f98..c3ec357d463 100644 --- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ForwardProxyServerTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ForwardProxyServerTest.java @@ -204,7 +204,7 @@ public class ForwardProxyServerTest ClientConnector clientConnector = new ClientConnector(); clientConnector.setSslContextFactory(clientTLS); HttpClient httpClient = new HttpClient(new HttpClientTransportOverHTTP(clientConnector)); - httpClient.getProxyConfiguration().getProxies().add(newHttpProxy()); + httpClient.getProxyConfiguration().addProxy(newHttpProxy()); httpClient.start(); try @@ -253,7 +253,7 @@ public class ForwardProxyServerTest }); HttpClient httpClient = new HttpClient(); - httpClient.getProxyConfiguration().getProxies().add(newHttpProxy()); + httpClient.getProxyConfiguration().addProxy(newHttpProxy()); httpClient.start(); ContentResponse response = httpClient.newRequest("[::1]", serverConnector.getLocalPort()) @@ -292,7 +292,7 @@ public class ForwardProxyServerTest }); HttpClient httpClient = new HttpClient(); - httpClient.getProxyConfiguration().getProxies().add(newHttpProxy()); + httpClient.getProxyConfiguration().addProxy(newHttpProxy()); httpClient.start(); ContentResponse response = httpClient.newRequest("[::1]", serverConnector.getLocalPort()) diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ForwardProxyTLSServerTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ForwardProxyTLSServerTest.java index 9c190a99db0..0b25a646fef 100644 --- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ForwardProxyTLSServerTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ForwardProxyTLSServerTest.java @@ -197,7 +197,7 @@ public class ForwardProxyTLSServerTest startProxy(proxyTLS); HttpClient httpClient = newHttpClient(); - httpClient.getProxyConfiguration().getProxies().add(newHttpProxy()); + httpClient.getProxyConfiguration().addProxy(newHttpProxy()); httpClient.start(); try @@ -232,7 +232,7 @@ public class ForwardProxyTLSServerTest startProxy(proxyTLS); HttpClient httpClient = newHttpClient(); - httpClient.getProxyConfiguration().getProxies().add(newHttpProxy()); + httpClient.getProxyConfiguration().addProxy(newHttpProxy()); httpClient.start(); try @@ -279,7 +279,7 @@ public class ForwardProxyTLSServerTest startProxy(proxyTLS); HttpClient httpClient = newHttpClient(); - httpClient.getProxyConfiguration().getProxies().add(newHttpProxy()); + httpClient.getProxyConfiguration().addProxy(newHttpProxy()); httpClient.start(); try @@ -364,7 +364,7 @@ public class ForwardProxyTLSServerTest }); HttpClient httpClient = newHttpClient(); - httpClient.getProxyConfiguration().getProxies().add(newHttpProxy()); + httpClient.getProxyConfiguration().addProxy(newHttpProxy()); // Short idle timeout for HttpClient. httpClient.setIdleTimeout(idleTimeout); httpClient.start(); @@ -402,7 +402,7 @@ public class ForwardProxyTLSServerTest stopProxy(); HttpClient httpClient = newHttpClient(); - httpClient.getProxyConfiguration().getProxies().add(new HttpProxy(new Origin.Address("localhost", proxyPort), proxySslContextFactory != null)); + httpClient.getProxyConfiguration().addProxy(new HttpProxy(new Origin.Address("localhost", proxyPort), proxySslContextFactory != null)); httpClient.start(); ExecutionException x = assertThrows(ExecutionException.class, () -> @@ -430,7 +430,7 @@ public class ForwardProxyTLSServerTest startProxy(proxyTLS); HttpClient httpClient = newHttpClient(); - httpClient.getProxyConfiguration().getProxies().add(newHttpProxy()); + httpClient.getProxyConfiguration().addProxy(newHttpProxy()); httpClient.start(); assertThrows(ExecutionException.class, () -> @@ -462,7 +462,7 @@ public class ForwardProxyTLSServerTest }); HttpClient httpClient = newHttpClient(); - httpClient.getProxyConfiguration().getProxies().add(newHttpProxy()); + httpClient.getProxyConfiguration().addProxy(newHttpProxy()); httpClient.start(); assertThrows(ExecutionException.class, () -> @@ -485,7 +485,7 @@ public class ForwardProxyTLSServerTest HttpClient httpClient = newHttpClient(); HttpProxy httpProxy = new HttpProxy(new Origin.Address("[::1]", proxyConnector.getLocalPort()), proxyTLS != null); - httpClient.getProxyConfiguration().getProxies().add(httpProxy); + httpClient.getProxyConfiguration().addProxy(httpProxy); httpClient.start(); try @@ -614,7 +614,7 @@ public class ForwardProxyTLSServerTest HttpProxy httpProxy = newHttpProxy(); if (includeAddress) httpProxy.getIncludedAddresses().add("localhost:" + serverConnector.getLocalPort()); - httpClient.getProxyConfiguration().getProxies().add(httpProxy); + httpClient.getProxyConfiguration().addProxy(httpProxy); URI uri = URI.create((proxySslContextFactory == null ? "http" : "https") + "://localhost:" + proxyConnector.getLocalPort()); httpClient.getAuthenticationStore().addAuthentication(new BasicAuthentication(uri, realm, "proxyUser", "proxyPassword")); httpClient.start(); @@ -696,7 +696,7 @@ public class ForwardProxyTLSServerTest clientConnector.setSelectors(1); clientConnector.setSslContextFactory(clientSslContextFactory); HttpClient httpClient = new HttpClient(new HttpClientTransportOverHTTP(clientConnector)); - httpClient.getProxyConfiguration().getProxies().add(newHttpProxy()); + httpClient.getProxyConfiguration().addProxy(newHttpProxy()); httpClient.start(); try @@ -767,7 +767,7 @@ public class ForwardProxyTLSServerTest proxyClientTLS.setEndpointIdentificationAlgorithm(null); proxyClientTLS.start(); HttpProxy httpProxy = new HttpProxy(new Origin.Address("localhost", proxyConnector.getLocalPort()), proxyClientTLS); - httpClient.getProxyConfiguration().getProxies().add(httpProxy); + httpClient.getProxyConfiguration().addProxy(httpProxy); httpClient.start(); try @@ -798,7 +798,7 @@ public class ForwardProxyTLSServerTest startProxy(proxyTLS); HttpClient httpClient = newHttpClient(); - httpClient.getProxyConfiguration().getProxies().add(newHttpProxy()); + httpClient.getProxyConfiguration().addProxy(newHttpProxy()); httpClient.start(); try @@ -847,7 +847,7 @@ public class ForwardProxyTLSServerTest }); startProxy(proxyTLS); HttpClient httpClient = newHttpClient(); - httpClient.getProxyConfiguration().getProxies().add(newHttpProxy()); + httpClient.getProxyConfiguration().addProxy(newHttpProxy()); httpClient.setConnectTimeout(timeout); httpClient.setIdleTimeout(4 * timeout); httpClient.start(); @@ -883,7 +883,7 @@ public class ForwardProxyTLSServerTest }); startProxy(proxyTLS); HttpClient httpClient = newHttpClient(); - httpClient.getProxyConfiguration().getProxies().add(newHttpProxy()); + httpClient.getProxyConfiguration().addProxy(newHttpProxy()); httpClient.setConnectTimeout(timeout); // Short idle timeout for HttpClient. httpClient.setIdleTimeout(timeout); @@ -929,7 +929,7 @@ public class ForwardProxyTLSServerTest } }); HttpClient httpClient = newHttpClient(); - httpClient.getProxyConfiguration().getProxies().add(newHttpProxy()); + httpClient.getProxyConfiguration().addProxy(newHttpProxy()); httpClient.setConnectTimeout(timeout); httpClient.setIdleTimeout(10 * timeout); httpClient.start(); @@ -978,7 +978,7 @@ public class ForwardProxyTLSServerTest } HttpClient httpClient = newHttpClient(); - httpClient.getProxyConfiguration().getProxies().add(new HttpProxy(proxyHost, proxyPort)); + httpClient.getProxyConfiguration().addProxy(new HttpProxy(proxyHost, proxyPort)); httpClient.start(); try diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletFailureTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletFailureTest.java index b891224b89b..ae4ef350c38 100644 --- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletFailureTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletFailureTest.java @@ -117,7 +117,7 @@ public class ProxyServletFailureTest QueuedThreadPool executor = new QueuedThreadPool(); executor.setName("client"); result.setExecutor(executor); - result.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", proxyConnector.getLocalPort())); + result.getProxyConfiguration().addProxy(new HttpProxy("localhost", proxyConnector.getLocalPort())); result.start(); return result; } diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletLoadTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletLoadTest.java index 5fcc4e67766..5cad85f9f25 100644 --- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletLoadTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletLoadTest.java @@ -109,7 +109,7 @@ public class ProxyServletLoadTest clientPool.setName("client"); HttpClient result = new HttpClient(); result.setExecutor(clientPool); - result.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", proxyConnector.getLocalPort())); + result.getProxyConfiguration().addProxy(new HttpProxy("localhost", proxyConnector.getLocalPort())); result.start(); client = result; } diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java index 7f804366de0..1a021a8985c 100644 --- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java @@ -62,6 +62,7 @@ import org.eclipse.jetty.client.ConnectionPool; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.HttpDestination; import org.eclipse.jetty.client.HttpProxy; +import org.eclipse.jetty.client.ProxyConfiguration.Proxy; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.client.api.Response; @@ -122,6 +123,7 @@ public class ProxyServletTest } private HttpClient client; + private Proxy clientProxy; private Server proxy; private ServerConnector proxyConnector; private ServletContextHandler proxyContext; @@ -196,6 +198,7 @@ public class ProxyServletTest private void startClient(Consumer consumer) throws Exception { + clientProxy = new HttpProxy("localhost", proxyConnector.getLocalPort()); client = prepareClient(consumer); } @@ -205,7 +208,7 @@ public class ProxyServletTest clientPool.setName("client"); HttpClient result = new HttpClient(); result.setExecutor(clientPool); - result.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", proxyConnector.getLocalPort())); + result.getProxyConfiguration().addProxy(clientProxy); if (consumer != null) consumer.accept(result); result.start(); @@ -728,7 +731,7 @@ public class ProxyServletTest startProxy(proxyServletClass); startClient(); int port = serverConnector.getLocalPort(); - client.getProxyConfiguration().getProxies().get(0).getExcludedAddresses().add("127.0.0.1:" + port); + clientProxy.getExcludedAddresses().add("127.0.0.1:" + port); // Try with a proxied host ContentResponse response = client.newRequest("localhost", port) diff --git a/jetty-unixdomain-server/src/test/java/org/eclipse/jetty/unixdomain/server/UnixDomainTest.java b/jetty-unixdomain-server/src/test/java/org/eclipse/jetty/unixdomain/server/UnixDomainTest.java index d5f7417a071..a86dfc7215b 100644 --- a/jetty-unixdomain-server/src/test/java/org/eclipse/jetty/unixdomain/server/UnixDomainTest.java +++ b/jetty-unixdomain-server/src/test/java/org/eclipse/jetty/unixdomain/server/UnixDomainTest.java @@ -175,7 +175,7 @@ public class UnixDomainTest ClientConnector clientConnector = ClientConnector.forUnixDomain(unixDomainPath); HttpClient httpClient = new HttpClient(new HttpClientTransportDynamic(clientConnector)); - httpClient.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", fakeProxyPort)); + httpClient.getProxyConfiguration().addProxy(new HttpProxy("localhost", fakeProxyPort)); httpClient.start(); try { diff --git a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientTransportDynamicTest.java b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientTransportDynamicTest.java index d349c23df5c..5844e0ee07b 100644 --- a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientTransportDynamicTest.java +++ b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientTransportDynamicTest.java @@ -586,7 +586,7 @@ public class HttpClientTransportDynamicTest int proxyPort = connector.getLocalPort(); // The proxy speaks both http/1.1 and h2c. Origin.Protocol proxyProtocol = new Origin.Protocol(List.of("http/1.1", "h2c"), false); - client.getProxyConfiguration().getProxies().add(new HttpProxy(new Origin.Address("localhost", proxyPort), false, proxyProtocol)); + client.getProxyConfiguration().addProxy(new HttpProxy(new Origin.Address("localhost", proxyPort), false, proxyProtocol)); // Make an upgrade request from HTTP/1.1 to H2C. int serverPort = proxyPort + 1; // Any port will do. diff --git a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/ProxyWithDynamicTransportTest.java b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/ProxyWithDynamicTransportTest.java index 9852927687b..72283fd20b8 100644 --- a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/ProxyWithDynamicTransportTest.java +++ b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/ProxyWithDynamicTransportTest.java @@ -260,7 +260,7 @@ public class ProxyWithDynamicTransportTest int proxyPort = proxySecure ? proxyTLSConnector.getLocalPort() : proxyConnector.getLocalPort(); Origin.Address proxyAddress = new Origin.Address("localhost", proxyPort); HttpProxy proxy = new HttpProxy(proxyAddress, proxySecure, proxyProtocol); - client.getProxyConfiguration().getProxies().add(proxy); + client.getProxyConfiguration().addProxy(proxy); String scheme = serverSecure ? "https" : "http"; int serverPort = serverSecure ? serverTLSConnector.getLocalPort() : serverConnector.getLocalPort(); @@ -296,7 +296,7 @@ public class ProxyWithDynamicTransportTest int proxyPort = proxyConnector.getLocalPort(); Origin.Address proxyAddress = new Origin.Address("localhost", proxyPort); HttpProxy proxy = new HttpProxy(proxyAddress, false, new Origin.Protocol(List.of("h2c"), false)); - client.getProxyConfiguration().getProxies().add(proxy); + client.getProxyConfiguration().addProxy(proxy); long idleTimeout = 1000; http2Client.setStreamIdleTimeout(idleTimeout); @@ -337,7 +337,7 @@ public class ProxyWithDynamicTransportTest int proxyPort = proxyConnector.getLocalPort(); Origin.Address proxyAddress = new Origin.Address("localhost", proxyPort); HttpProxy httpProxy = new HttpProxy(proxyAddress, false, new Origin.Protocol(List.of("h2c"), false)); - client.getProxyConfiguration().getProxies().add(httpProxy); + client.getProxyConfiguration().addProxy(httpProxy); proxy.stop(); CountDownLatch latch = new CountDownLatch(1); @@ -372,7 +372,7 @@ public class ProxyWithDynamicTransportTest int proxyPort = proxyConnector.getLocalPort(); Origin.Address proxyAddress = new Origin.Address("localhost", proxyPort); HttpProxy httpProxy = new HttpProxy(proxyAddress, false, new Origin.Protocol(List.of("h2c"), false)); - client.getProxyConfiguration().getProxies().add(httpProxy); + client.getProxyConfiguration().addProxy(httpProxy); CountDownLatch latch = new CountDownLatch(1); client.newRequest("localhost", serverConnector.getLocalPort())