Merged branch 'cowwoc-jetty-10.0.x-8723-provide-a-thread-safe-way-to-modify-proxies-at-runtime' into 'jetty-10.0.x'.
This commit is contained in:
commit
94c6e63b76
|
@ -40,7 +40,7 @@ public class ProxyServerTest extends AbstractEmbeddedTest
|
||||||
server.start();
|
server.start();
|
||||||
|
|
||||||
URI uri = server.getURI();
|
URI uri = server.getURI();
|
||||||
client.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", uri.getPort()));
|
client.getProxyConfiguration().addProxy(new HttpProxy("localhost", uri.getPort()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
|
|
|
@ -659,7 +659,7 @@ public class HTTPClientDocs
|
||||||
|
|
||||||
// Add the new proxy to the list of proxies already registered.
|
// Add the new proxy to the list of proxies already registered.
|
||||||
ProxyConfiguration proxyConfig = httpClient.getProxyConfiguration();
|
ProxyConfiguration proxyConfig = httpClient.getProxyConfiguration();
|
||||||
proxyConfig.getProxies().add(proxy);
|
proxyConfig.addProxy(proxy);
|
||||||
|
|
||||||
ContentResponse response = httpClient.GET("http://domain.com/path");
|
ContentResponse response = httpClient.GET("http://domain.com/path");
|
||||||
// end::proxy[]
|
// end::proxy[]
|
||||||
|
@ -684,7 +684,7 @@ public class HTTPClientDocs
|
||||||
// Proxy configuration.
|
// Proxy configuration.
|
||||||
ProxyConfiguration proxyConfig = httpClient.getProxyConfiguration();
|
ProxyConfiguration proxyConfig = httpClient.getProxyConfiguration();
|
||||||
HttpProxy proxy = new HttpProxy("proxy.net", 8080);
|
HttpProxy proxy = new HttpProxy("proxy.net", 8080);
|
||||||
proxyConfig.getProxies().add(proxy);
|
proxyConfig.addProxy(proxy);
|
||||||
|
|
||||||
ContentResponse response = httpClient.newRequest(serverURI).send();
|
ContentResponse response = httpClient.newRequest(serverURI).send();
|
||||||
// end::proxyAuthentication[]
|
// end::proxyAuthentication[]
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class WebSocketClientDocs
|
||||||
// Instantiate and configure HttpClient.
|
// Instantiate and configure HttpClient.
|
||||||
HttpClient httpClient = new HttpClient();
|
HttpClient httpClient = new HttpClient();
|
||||||
// For example, configure a proxy.
|
// 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.
|
// Instantiate WebSocketClient, passing HttpClient to the constructor.
|
||||||
WebSocketClient webSocketClient = new WebSocketClient(httpClient);
|
WebSocketClient webSocketClient = new WebSocketClient(httpClient);
|
||||||
|
|
|
@ -14,13 +14,14 @@
|
||||||
package org.eclipse.jetty.client;
|
package org.eclipse.jetty.client;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.jetty.http.HttpScheme;
|
import org.eclipse.jetty.http.HttpScheme;
|
||||||
import org.eclipse.jetty.io.ClientConnectionFactory;
|
import org.eclipse.jetty.io.ClientConnectionFactory;
|
||||||
|
import org.eclipse.jetty.util.BlockingArrayQueue;
|
||||||
import org.eclipse.jetty.util.HostPort;
|
import org.eclipse.jetty.util.HostPort;
|
||||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
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:
|
* Applications add subclasses of {@link Proxy} to this configuration via:
|
||||||
* <pre>
|
* <pre>
|
||||||
* ProxyConfiguration proxyConfig = httpClient.getProxyConfiguration();
|
* ProxyConfiguration proxyConfig = httpClient.getProxyConfiguration();
|
||||||
* proxyConfig.getProxies().add(new HttpProxy(proxyHost, 8080));
|
* proxyConfig.addProxy(new HttpProxy(proxyHost, 8080));
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @see HttpClient#getProxyConfiguration()
|
* @see HttpClient#getProxyConfiguration()
|
||||||
*/
|
*/
|
||||||
public class ProxyConfiguration
|
public class ProxyConfiguration
|
||||||
{
|
{
|
||||||
private final List<Proxy> proxies = new ArrayList<>();
|
private final List<Proxy> proxies = new BlockingArrayQueue<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use {@link #addProxy(Proxy)} and {@link #removeProxy(Proxy)} instead
|
||||||
|
* @return the forward proxies to use
|
||||||
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public List<Proxy> getProxies()
|
public List<Proxy> getProxies()
|
||||||
{
|
{
|
||||||
return proxies;
|
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)
|
public Proxy match(Origin origin)
|
||||||
{
|
{
|
||||||
for (Proxy proxy : getProxies())
|
for (Proxy proxy : proxies)
|
||||||
{
|
{
|
||||||
if (proxy.matches(origin))
|
if (proxy.matches(origin))
|
||||||
return proxy;
|
return proxy;
|
||||||
|
|
|
@ -98,7 +98,7 @@ public class HttpClientCustomProxyTest
|
||||||
// Setup the custom proxy
|
// Setup the custom proxy
|
||||||
int proxyPort = connector.getLocalPort();
|
int proxyPort = connector.getLocalPort();
|
||||||
int serverPort = proxyPort + 1; // Any port will do for these tests - just not the same as the proxy
|
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)
|
ContentResponse response = client.newRequest(serverHost, serverPort)
|
||||||
.timeout(5, TimeUnit.SECONDS)
|
.timeout(5, TimeUnit.SECONDS)
|
||||||
|
|
|
@ -231,7 +231,7 @@ public class HttpClientProxyProtocolTest
|
||||||
|
|
||||||
int proxyPort = connector.getLocalPort();
|
int proxyPort = connector.getLocalPort();
|
||||||
int serverPort = proxyPort + 1; // Any port will do.
|
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.
|
// 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.
|
// The server is configured with the PROXY protocol to know the socket address of clients.
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class HttpClientProxyTest extends AbstractHttpClientServerTest
|
||||||
|
|
||||||
int proxyPort = connector.getLocalPort();
|
int proxyPort = connector.getLocalPort();
|
||||||
int serverPort = proxyPort + 1; // Any port will do for these tests - just not the same as the proxy
|
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)
|
ContentResponse response = client.newRequest(serverHost, serverPort)
|
||||||
.scheme(scenario.getScheme())
|
.scheme(scenario.getScheme())
|
||||||
|
@ -108,7 +108,7 @@ public class HttpClientProxyTest extends AbstractHttpClientServerTest
|
||||||
String proxyHost = "localhost";
|
String proxyHost = "localhost";
|
||||||
int proxyPort = connector.getLocalPort();
|
int proxyPort = connector.getLocalPort();
|
||||||
int serverPort = proxyPort + 1; // Any port will do for these tests - just not the same as the proxy
|
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)
|
ContentResponse response1 = client.newRequest(serverHost, serverPort)
|
||||||
.scheme(scenario.getScheme())
|
.scheme(scenario.getScheme())
|
||||||
|
@ -202,7 +202,7 @@ public class HttpClientProxyTest extends AbstractHttpClientServerTest
|
||||||
});
|
});
|
||||||
|
|
||||||
int proxyPort = connector.getLocalPort();
|
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)
|
ContentResponse response1 = client.newRequest(serverHost, serverPort)
|
||||||
.scheme(scenario.getScheme())
|
.scheme(scenario.getScheme())
|
||||||
|
@ -290,7 +290,7 @@ public class HttpClientProxyTest extends AbstractHttpClientServerTest
|
||||||
client.getAuthenticationStore().addAuthentication(new BasicAuthentication(proxyURI, proxyRealm, "proxyUser", "proxyPassword"));
|
client.getAuthenticationStore().addAuthentication(new BasicAuthentication(proxyURI, proxyRealm, "proxyUser", "proxyPassword"));
|
||||||
URI serverURI = URI.create(scenario.getScheme() + "://" + serverHost + ":" + serverPort);
|
URI serverURI = URI.create(scenario.getScheme() + "://" + serverHost + ":" + serverPort);
|
||||||
client.getAuthenticationStore().addAuthentication(new BasicAuthentication(serverURI, serverRealm, "serverUser", "serverPassword"));
|
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();
|
final AtomicInteger requests = new AtomicInteger();
|
||||||
client.getRequestListeners().add(new Request.Listener.Adapter()
|
client.getRequestListeners().add(new Request.Listener.Adapter()
|
||||||
{
|
{
|
||||||
|
@ -361,7 +361,7 @@ public class HttpClientProxyTest extends AbstractHttpClientServerTest
|
||||||
int serverPort = proxyPort + 1;
|
int serverPort = proxyPort + 1;
|
||||||
URI proxyURI = URI.create(scenario.getScheme() + "://" + proxyHost + ":" + proxyPort);
|
URI proxyURI = URI.create(scenario.getScheme() + "://" + proxyHost + ":" + proxyPort);
|
||||||
client.getAuthenticationStore().addAuthentication(new BasicAuthentication(proxyURI, proxyRealm, "proxyUser", "proxyPassword"));
|
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();
|
final AtomicInteger requests = new AtomicInteger();
|
||||||
client.getRequestListeners().add(new Request.Listener.Adapter()
|
client.getRequestListeners().add(new Request.Listener.Adapter()
|
||||||
{
|
{
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class Socks4ProxyTest
|
||||||
public void testSocks4Proxy() throws Exception
|
public void testSocks4Proxy() throws Exception
|
||||||
{
|
{
|
||||||
int proxyPort = proxy.socket().getLocalPort();
|
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);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ public class Socks4ProxyTest
|
||||||
public void testSocks4ProxyWithSplitResponse() throws Exception
|
public void testSocks4ProxyWithSplitResponse() throws Exception
|
||||||
{
|
{
|
||||||
int proxyPort = proxy.socket().getLocalPort();
|
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);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ public class Socks4ProxyTest
|
||||||
// The hostname must be that of the server, not of the proxy.
|
// The hostname must be that of the server, not of the proxy.
|
||||||
ssl.setHostnameVerifier((hostname, session) -> serverHost.equals(hostname));
|
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);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
client.newRequest(serverHost, serverPort)
|
client.newRequest(serverHost, serverPort)
|
||||||
|
@ -283,7 +283,7 @@ public class Socks4ProxyTest
|
||||||
{
|
{
|
||||||
String proxyHost = "localhost";
|
String proxyHost = "localhost";
|
||||||
int proxyPort = proxy.socket().getLocalPort();
|
int proxyPort = proxy.socket().getLocalPort();
|
||||||
client.getProxyConfiguration().getProxies().add(new Socks4Proxy(proxyHost, proxyPort));
|
client.getProxyConfiguration().addProxy(new Socks4Proxy(proxyHost, proxyPort));
|
||||||
|
|
||||||
long timeout = 1000;
|
long timeout = 1000;
|
||||||
Request request = client.newRequest("localhost", proxyPort + 1)
|
Request request = client.newRequest("localhost", proxyPort + 1)
|
||||||
|
@ -305,7 +305,7 @@ public class Socks4ProxyTest
|
||||||
{
|
{
|
||||||
String proxyHost = "localhost";
|
String proxyHost = "localhost";
|
||||||
int proxyPort = proxy.socket().getLocalPort();
|
int proxyPort = proxy.socket().getLocalPort();
|
||||||
client.getProxyConfiguration().getProxies().add(new Socks4Proxy(proxyHost, proxyPort));
|
client.getProxyConfiguration().addProxy(new Socks4Proxy(proxyHost, proxyPort));
|
||||||
long idleTimeout = 1000;
|
long idleTimeout = 1000;
|
||||||
client.setIdleTimeout(idleTimeout);
|
client.setIdleTimeout(idleTimeout);
|
||||||
|
|
||||||
|
@ -327,7 +327,7 @@ public class Socks4ProxyTest
|
||||||
{
|
{
|
||||||
String proxyHost = "localhost";
|
String proxyHost = "localhost";
|
||||||
int proxyPort = proxy.socket().getLocalPort();
|
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);
|
Request request = client.newRequest("localhost", proxyPort + 1);
|
||||||
FutureResponseListener listener = new FutureResponseListener(request);
|
FutureResponseListener listener = new FutureResponseListener(request);
|
||||||
|
|
|
@ -345,7 +345,7 @@ public class HttpClientTransportOverHTTP2Test extends AbstractTest
|
||||||
});
|
});
|
||||||
|
|
||||||
int proxyPort = connector.getLocalPort();
|
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.
|
int serverPort = proxyPort + 1; // Any port will do, just not the same as the proxy.
|
||||||
ContentResponse response = client.newRequest("localhost", serverPort)
|
ContentResponse response = client.newRequest("localhost", serverPort)
|
||||||
|
|
|
@ -152,7 +152,7 @@ public class AsyncMiddleManServletTest
|
||||||
clientPool.setName("client");
|
clientPool.setName("client");
|
||||||
client = new HttpClient();
|
client = new HttpClient();
|
||||||
client.setExecutor(clientPool);
|
client.setExecutor(clientPool);
|
||||||
client.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", proxyConnector.getLocalPort()));
|
client.getProxyConfiguration().addProxy(new HttpProxy("localhost", proxyConnector.getLocalPort()));
|
||||||
client.start();
|
client.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -204,7 +204,7 @@ public class ForwardProxyServerTest
|
||||||
ClientConnector clientConnector = new ClientConnector();
|
ClientConnector clientConnector = new ClientConnector();
|
||||||
clientConnector.setSslContextFactory(clientTLS);
|
clientConnector.setSslContextFactory(clientTLS);
|
||||||
HttpClient httpClient = new HttpClient(new HttpClientTransportOverHTTP(clientConnector));
|
HttpClient httpClient = new HttpClient(new HttpClientTransportOverHTTP(clientConnector));
|
||||||
httpClient.getProxyConfiguration().getProxies().add(newHttpProxy());
|
httpClient.getProxyConfiguration().addProxy(newHttpProxy());
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -253,7 +253,7 @@ public class ForwardProxyServerTest
|
||||||
});
|
});
|
||||||
|
|
||||||
HttpClient httpClient = new HttpClient();
|
HttpClient httpClient = new HttpClient();
|
||||||
httpClient.getProxyConfiguration().getProxies().add(newHttpProxy());
|
httpClient.getProxyConfiguration().addProxy(newHttpProxy());
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
|
|
||||||
ContentResponse response = httpClient.newRequest("[::1]", serverConnector.getLocalPort())
|
ContentResponse response = httpClient.newRequest("[::1]", serverConnector.getLocalPort())
|
||||||
|
@ -292,7 +292,7 @@ public class ForwardProxyServerTest
|
||||||
});
|
});
|
||||||
|
|
||||||
HttpClient httpClient = new HttpClient();
|
HttpClient httpClient = new HttpClient();
|
||||||
httpClient.getProxyConfiguration().getProxies().add(newHttpProxy());
|
httpClient.getProxyConfiguration().addProxy(newHttpProxy());
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
|
|
||||||
ContentResponse response = httpClient.newRequest("[::1]", serverConnector.getLocalPort())
|
ContentResponse response = httpClient.newRequest("[::1]", serverConnector.getLocalPort())
|
||||||
|
|
|
@ -197,7 +197,7 @@ public class ForwardProxyTLSServerTest
|
||||||
startProxy(proxyTLS);
|
startProxy(proxyTLS);
|
||||||
|
|
||||||
HttpClient httpClient = newHttpClient();
|
HttpClient httpClient = newHttpClient();
|
||||||
httpClient.getProxyConfiguration().getProxies().add(newHttpProxy());
|
httpClient.getProxyConfiguration().addProxy(newHttpProxy());
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -232,7 +232,7 @@ public class ForwardProxyTLSServerTest
|
||||||
startProxy(proxyTLS);
|
startProxy(proxyTLS);
|
||||||
|
|
||||||
HttpClient httpClient = newHttpClient();
|
HttpClient httpClient = newHttpClient();
|
||||||
httpClient.getProxyConfiguration().getProxies().add(newHttpProxy());
|
httpClient.getProxyConfiguration().addProxy(newHttpProxy());
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -279,7 +279,7 @@ public class ForwardProxyTLSServerTest
|
||||||
startProxy(proxyTLS);
|
startProxy(proxyTLS);
|
||||||
|
|
||||||
HttpClient httpClient = newHttpClient();
|
HttpClient httpClient = newHttpClient();
|
||||||
httpClient.getProxyConfiguration().getProxies().add(newHttpProxy());
|
httpClient.getProxyConfiguration().addProxy(newHttpProxy());
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -364,7 +364,7 @@ public class ForwardProxyTLSServerTest
|
||||||
});
|
});
|
||||||
|
|
||||||
HttpClient httpClient = newHttpClient();
|
HttpClient httpClient = newHttpClient();
|
||||||
httpClient.getProxyConfiguration().getProxies().add(newHttpProxy());
|
httpClient.getProxyConfiguration().addProxy(newHttpProxy());
|
||||||
// Short idle timeout for HttpClient.
|
// Short idle timeout for HttpClient.
|
||||||
httpClient.setIdleTimeout(idleTimeout);
|
httpClient.setIdleTimeout(idleTimeout);
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
|
@ -402,7 +402,7 @@ public class ForwardProxyTLSServerTest
|
||||||
stopProxy();
|
stopProxy();
|
||||||
|
|
||||||
HttpClient httpClient = newHttpClient();
|
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();
|
httpClient.start();
|
||||||
|
|
||||||
ExecutionException x = assertThrows(ExecutionException.class, () ->
|
ExecutionException x = assertThrows(ExecutionException.class, () ->
|
||||||
|
@ -430,7 +430,7 @@ public class ForwardProxyTLSServerTest
|
||||||
startProxy(proxyTLS);
|
startProxy(proxyTLS);
|
||||||
|
|
||||||
HttpClient httpClient = newHttpClient();
|
HttpClient httpClient = newHttpClient();
|
||||||
httpClient.getProxyConfiguration().getProxies().add(newHttpProxy());
|
httpClient.getProxyConfiguration().addProxy(newHttpProxy());
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
|
|
||||||
assertThrows(ExecutionException.class, () ->
|
assertThrows(ExecutionException.class, () ->
|
||||||
|
@ -462,7 +462,7 @@ public class ForwardProxyTLSServerTest
|
||||||
});
|
});
|
||||||
|
|
||||||
HttpClient httpClient = newHttpClient();
|
HttpClient httpClient = newHttpClient();
|
||||||
httpClient.getProxyConfiguration().getProxies().add(newHttpProxy());
|
httpClient.getProxyConfiguration().addProxy(newHttpProxy());
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
|
|
||||||
assertThrows(ExecutionException.class, () ->
|
assertThrows(ExecutionException.class, () ->
|
||||||
|
@ -485,7 +485,7 @@ public class ForwardProxyTLSServerTest
|
||||||
|
|
||||||
HttpClient httpClient = newHttpClient();
|
HttpClient httpClient = newHttpClient();
|
||||||
HttpProxy httpProxy = new HttpProxy(new Origin.Address("[::1]", proxyConnector.getLocalPort()), proxyTLS != null);
|
HttpProxy httpProxy = new HttpProxy(new Origin.Address("[::1]", proxyConnector.getLocalPort()), proxyTLS != null);
|
||||||
httpClient.getProxyConfiguration().getProxies().add(httpProxy);
|
httpClient.getProxyConfiguration().addProxy(httpProxy);
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -614,7 +614,7 @@ public class ForwardProxyTLSServerTest
|
||||||
HttpProxy httpProxy = newHttpProxy();
|
HttpProxy httpProxy = newHttpProxy();
|
||||||
if (includeAddress)
|
if (includeAddress)
|
||||||
httpProxy.getIncludedAddresses().add("localhost:" + serverConnector.getLocalPort());
|
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());
|
URI uri = URI.create((proxySslContextFactory == null ? "http" : "https") + "://localhost:" + proxyConnector.getLocalPort());
|
||||||
httpClient.getAuthenticationStore().addAuthentication(new BasicAuthentication(uri, realm, "proxyUser", "proxyPassword"));
|
httpClient.getAuthenticationStore().addAuthentication(new BasicAuthentication(uri, realm, "proxyUser", "proxyPassword"));
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
|
@ -696,7 +696,7 @@ public class ForwardProxyTLSServerTest
|
||||||
clientConnector.setSelectors(1);
|
clientConnector.setSelectors(1);
|
||||||
clientConnector.setSslContextFactory(clientSslContextFactory);
|
clientConnector.setSslContextFactory(clientSslContextFactory);
|
||||||
HttpClient httpClient = new HttpClient(new HttpClientTransportOverHTTP(clientConnector));
|
HttpClient httpClient = new HttpClient(new HttpClientTransportOverHTTP(clientConnector));
|
||||||
httpClient.getProxyConfiguration().getProxies().add(newHttpProxy());
|
httpClient.getProxyConfiguration().addProxy(newHttpProxy());
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -767,7 +767,7 @@ public class ForwardProxyTLSServerTest
|
||||||
proxyClientTLS.setEndpointIdentificationAlgorithm(null);
|
proxyClientTLS.setEndpointIdentificationAlgorithm(null);
|
||||||
proxyClientTLS.start();
|
proxyClientTLS.start();
|
||||||
HttpProxy httpProxy = new HttpProxy(new Origin.Address("localhost", proxyConnector.getLocalPort()), proxyClientTLS);
|
HttpProxy httpProxy = new HttpProxy(new Origin.Address("localhost", proxyConnector.getLocalPort()), proxyClientTLS);
|
||||||
httpClient.getProxyConfiguration().getProxies().add(httpProxy);
|
httpClient.getProxyConfiguration().addProxy(httpProxy);
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -798,7 +798,7 @@ public class ForwardProxyTLSServerTest
|
||||||
startProxy(proxyTLS);
|
startProxy(proxyTLS);
|
||||||
|
|
||||||
HttpClient httpClient = newHttpClient();
|
HttpClient httpClient = newHttpClient();
|
||||||
httpClient.getProxyConfiguration().getProxies().add(newHttpProxy());
|
httpClient.getProxyConfiguration().addProxy(newHttpProxy());
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -847,7 +847,7 @@ public class ForwardProxyTLSServerTest
|
||||||
});
|
});
|
||||||
startProxy(proxyTLS);
|
startProxy(proxyTLS);
|
||||||
HttpClient httpClient = newHttpClient();
|
HttpClient httpClient = newHttpClient();
|
||||||
httpClient.getProxyConfiguration().getProxies().add(newHttpProxy());
|
httpClient.getProxyConfiguration().addProxy(newHttpProxy());
|
||||||
httpClient.setConnectTimeout(timeout);
|
httpClient.setConnectTimeout(timeout);
|
||||||
httpClient.setIdleTimeout(4 * timeout);
|
httpClient.setIdleTimeout(4 * timeout);
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
|
@ -883,7 +883,7 @@ public class ForwardProxyTLSServerTest
|
||||||
});
|
});
|
||||||
startProxy(proxyTLS);
|
startProxy(proxyTLS);
|
||||||
HttpClient httpClient = newHttpClient();
|
HttpClient httpClient = newHttpClient();
|
||||||
httpClient.getProxyConfiguration().getProxies().add(newHttpProxy());
|
httpClient.getProxyConfiguration().addProxy(newHttpProxy());
|
||||||
httpClient.setConnectTimeout(timeout);
|
httpClient.setConnectTimeout(timeout);
|
||||||
// Short idle timeout for HttpClient.
|
// Short idle timeout for HttpClient.
|
||||||
httpClient.setIdleTimeout(timeout);
|
httpClient.setIdleTimeout(timeout);
|
||||||
|
@ -929,7 +929,7 @@ public class ForwardProxyTLSServerTest
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
HttpClient httpClient = newHttpClient();
|
HttpClient httpClient = newHttpClient();
|
||||||
httpClient.getProxyConfiguration().getProxies().add(newHttpProxy());
|
httpClient.getProxyConfiguration().addProxy(newHttpProxy());
|
||||||
httpClient.setConnectTimeout(timeout);
|
httpClient.setConnectTimeout(timeout);
|
||||||
httpClient.setIdleTimeout(10 * timeout);
|
httpClient.setIdleTimeout(10 * timeout);
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
|
@ -978,7 +978,7 @@ public class ForwardProxyTLSServerTest
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpClient httpClient = newHttpClient();
|
HttpClient httpClient = newHttpClient();
|
||||||
httpClient.getProxyConfiguration().getProxies().add(new HttpProxy(proxyHost, proxyPort));
|
httpClient.getProxyConfiguration().addProxy(new HttpProxy(proxyHost, proxyPort));
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
|
@ -117,7 +117,7 @@ public class ProxyServletFailureTest
|
||||||
QueuedThreadPool executor = new QueuedThreadPool();
|
QueuedThreadPool executor = new QueuedThreadPool();
|
||||||
executor.setName("client");
|
executor.setName("client");
|
||||||
result.setExecutor(executor);
|
result.setExecutor(executor);
|
||||||
result.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", proxyConnector.getLocalPort()));
|
result.getProxyConfiguration().addProxy(new HttpProxy("localhost", proxyConnector.getLocalPort()));
|
||||||
result.start();
|
result.start();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ public class ProxyServletLoadTest
|
||||||
clientPool.setName("client");
|
clientPool.setName("client");
|
||||||
HttpClient result = new HttpClient();
|
HttpClient result = new HttpClient();
|
||||||
result.setExecutor(clientPool);
|
result.setExecutor(clientPool);
|
||||||
result.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", proxyConnector.getLocalPort()));
|
result.getProxyConfiguration().addProxy(new HttpProxy("localhost", proxyConnector.getLocalPort()));
|
||||||
result.start();
|
result.start();
|
||||||
client = result;
|
client = result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ import org.eclipse.jetty.client.ConnectionPool;
|
||||||
import org.eclipse.jetty.client.HttpClient;
|
import org.eclipse.jetty.client.HttpClient;
|
||||||
import org.eclipse.jetty.client.HttpDestination;
|
import org.eclipse.jetty.client.HttpDestination;
|
||||||
import org.eclipse.jetty.client.HttpProxy;
|
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.ContentResponse;
|
||||||
import org.eclipse.jetty.client.api.Request;
|
import org.eclipse.jetty.client.api.Request;
|
||||||
import org.eclipse.jetty.client.api.Response;
|
import org.eclipse.jetty.client.api.Response;
|
||||||
|
@ -122,6 +123,7 @@ public class ProxyServletTest
|
||||||
}
|
}
|
||||||
|
|
||||||
private HttpClient client;
|
private HttpClient client;
|
||||||
|
private Proxy clientProxy;
|
||||||
private Server proxy;
|
private Server proxy;
|
||||||
private ServerConnector proxyConnector;
|
private ServerConnector proxyConnector;
|
||||||
private ServletContextHandler proxyContext;
|
private ServletContextHandler proxyContext;
|
||||||
|
@ -196,6 +198,7 @@ public class ProxyServletTest
|
||||||
|
|
||||||
private void startClient(Consumer<HttpClient> consumer) throws Exception
|
private void startClient(Consumer<HttpClient> consumer) throws Exception
|
||||||
{
|
{
|
||||||
|
clientProxy = new HttpProxy("localhost", proxyConnector.getLocalPort());
|
||||||
client = prepareClient(consumer);
|
client = prepareClient(consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +208,7 @@ public class ProxyServletTest
|
||||||
clientPool.setName("client");
|
clientPool.setName("client");
|
||||||
HttpClient result = new HttpClient();
|
HttpClient result = new HttpClient();
|
||||||
result.setExecutor(clientPool);
|
result.setExecutor(clientPool);
|
||||||
result.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", proxyConnector.getLocalPort()));
|
result.getProxyConfiguration().addProxy(clientProxy);
|
||||||
if (consumer != null)
|
if (consumer != null)
|
||||||
consumer.accept(result);
|
consumer.accept(result);
|
||||||
result.start();
|
result.start();
|
||||||
|
@ -728,7 +731,7 @@ public class ProxyServletTest
|
||||||
startProxy(proxyServletClass);
|
startProxy(proxyServletClass);
|
||||||
startClient();
|
startClient();
|
||||||
int port = serverConnector.getLocalPort();
|
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
|
// Try with a proxied host
|
||||||
ContentResponse response = client.newRequest("localhost", port)
|
ContentResponse response = client.newRequest("localhost", port)
|
||||||
|
|
|
@ -175,7 +175,7 @@ public class UnixDomainTest
|
||||||
ClientConnector clientConnector = ClientConnector.forUnixDomain(unixDomainPath);
|
ClientConnector clientConnector = ClientConnector.forUnixDomain(unixDomainPath);
|
||||||
|
|
||||||
HttpClient httpClient = new HttpClient(new HttpClientTransportDynamic(clientConnector));
|
HttpClient httpClient = new HttpClient(new HttpClientTransportDynamic(clientConnector));
|
||||||
httpClient.getProxyConfiguration().getProxies().add(new HttpProxy("localhost", fakeProxyPort));
|
httpClient.getProxyConfiguration().addProxy(new HttpProxy("localhost", fakeProxyPort));
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -586,7 +586,7 @@ public class HttpClientTransportDynamicTest
|
||||||
int proxyPort = connector.getLocalPort();
|
int proxyPort = connector.getLocalPort();
|
||||||
// The proxy speaks both http/1.1 and h2c.
|
// The proxy speaks both http/1.1 and h2c.
|
||||||
Origin.Protocol proxyProtocol = new Origin.Protocol(List.of("http/1.1", "h2c"), false);
|
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.
|
// Make an upgrade request from HTTP/1.1 to H2C.
|
||||||
int serverPort = proxyPort + 1; // Any port will do.
|
int serverPort = proxyPort + 1; // Any port will do.
|
||||||
|
|
|
@ -260,7 +260,7 @@ public class ProxyWithDynamicTransportTest
|
||||||
int proxyPort = proxySecure ? proxyTLSConnector.getLocalPort() : proxyConnector.getLocalPort();
|
int proxyPort = proxySecure ? proxyTLSConnector.getLocalPort() : proxyConnector.getLocalPort();
|
||||||
Origin.Address proxyAddress = new Origin.Address("localhost", proxyPort);
|
Origin.Address proxyAddress = new Origin.Address("localhost", proxyPort);
|
||||||
HttpProxy proxy = new HttpProxy(proxyAddress, proxySecure, proxyProtocol);
|
HttpProxy proxy = new HttpProxy(proxyAddress, proxySecure, proxyProtocol);
|
||||||
client.getProxyConfiguration().getProxies().add(proxy);
|
client.getProxyConfiguration().addProxy(proxy);
|
||||||
|
|
||||||
String scheme = serverSecure ? "https" : "http";
|
String scheme = serverSecure ? "https" : "http";
|
||||||
int serverPort = serverSecure ? serverTLSConnector.getLocalPort() : serverConnector.getLocalPort();
|
int serverPort = serverSecure ? serverTLSConnector.getLocalPort() : serverConnector.getLocalPort();
|
||||||
|
@ -296,7 +296,7 @@ public class ProxyWithDynamicTransportTest
|
||||||
int proxyPort = proxyConnector.getLocalPort();
|
int proxyPort = proxyConnector.getLocalPort();
|
||||||
Origin.Address proxyAddress = new Origin.Address("localhost", proxyPort);
|
Origin.Address proxyAddress = new Origin.Address("localhost", proxyPort);
|
||||||
HttpProxy proxy = new HttpProxy(proxyAddress, false, new Origin.Protocol(List.of("h2c"), false));
|
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;
|
long idleTimeout = 1000;
|
||||||
http2Client.setStreamIdleTimeout(idleTimeout);
|
http2Client.setStreamIdleTimeout(idleTimeout);
|
||||||
|
@ -337,7 +337,7 @@ public class ProxyWithDynamicTransportTest
|
||||||
int proxyPort = proxyConnector.getLocalPort();
|
int proxyPort = proxyConnector.getLocalPort();
|
||||||
Origin.Address proxyAddress = new Origin.Address("localhost", proxyPort);
|
Origin.Address proxyAddress = new Origin.Address("localhost", proxyPort);
|
||||||
HttpProxy httpProxy = new HttpProxy(proxyAddress, false, new Origin.Protocol(List.of("h2c"), false));
|
HttpProxy httpProxy = new HttpProxy(proxyAddress, false, new Origin.Protocol(List.of("h2c"), false));
|
||||||
client.getProxyConfiguration().getProxies().add(httpProxy);
|
client.getProxyConfiguration().addProxy(httpProxy);
|
||||||
proxy.stop();
|
proxy.stop();
|
||||||
|
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
@ -372,7 +372,7 @@ public class ProxyWithDynamicTransportTest
|
||||||
int proxyPort = proxyConnector.getLocalPort();
|
int proxyPort = proxyConnector.getLocalPort();
|
||||||
Origin.Address proxyAddress = new Origin.Address("localhost", proxyPort);
|
Origin.Address proxyAddress = new Origin.Address("localhost", proxyPort);
|
||||||
HttpProxy httpProxy = new HttpProxy(proxyAddress, false, new Origin.Protocol(List.of("h2c"), false));
|
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);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
client.newRequest("localhost", serverConnector.getLocalPort())
|
client.newRequest("localhost", serverConnector.getLocalPort())
|
||||||
|
|
Loading…
Reference in New Issue