diff --git a/src/main/java/com/spotify/docker/client/DefaultDockerClient.java b/src/main/java/com/spotify/docker/client/DefaultDockerClient.java index 48db01591..1a7ddbfbc 100644 --- a/src/main/java/com/spotify/docker/client/DefaultDockerClient.java +++ b/src/main/java/com/spotify/docker/client/DefaultDockerClient.java @@ -444,7 +444,7 @@ private ClientConfig updateProxy(ClientConfig config, Builder builder) { final String proxyHost = System.getProperty("http.proxyHost"); if (proxyHost != null) { String proxyPort = checkNotNull(System.getProperty("http.proxyPort"), "http.proxyPort"); - config.property(ClientProperties.PROXY_URI, !proxyHost.startsWith("http") ? "http://" : "" + config.property(ClientProperties.PROXY_URI, (!proxyHost.startsWith("http") ? "http://" : "") + proxyHost + ":" + proxyPort); final String proxyUser = System.getProperty("http.proxyUser"); if (proxyUser != null) { diff --git a/src/test/java/com/spotify/docker/client/DefaultDockerClientUnitTest.java b/src/test/java/com/spotify/docker/client/DefaultDockerClientUnitTest.java index 22d89d67e..73ef5d08a 100644 --- a/src/test/java/com/spotify/docker/client/DefaultDockerClientUnitTest.java +++ b/src/test/java/com/spotify/docker/client/DefaultDockerClientUnitTest.java @@ -166,6 +166,22 @@ public void testHostForIpHttps() { assertThat(client.getHost(), equalTo("192.168.53.103")); } + @Test + public void testHostWithProxy() { + try { + System.setProperty("http.proxyHost", "gmodules.com"); + System.setProperty("http.proxyPort", "80"); + final DefaultDockerClient client = DefaultDockerClient.builder() + .uri("https://192.168.53.103:2375").build(); + assertThat((String) client.getClient().getConfiguration() + .getProperty("jersey.config.client.proxy.uri"), + equalTo("http://gmodules.com:80")); + } finally { + System.clearProperty("http.proxyHost"); + System.clearProperty("http.proxyPort"); + } + } + private RecordedRequest takeRequestImmediately() throws InterruptedException { return server.takeRequest(1, TimeUnit.MILLISECONDS); }