Skip to content

Commit 4f5a275

Browse files
alregadavidxia
authored andcommitted
Fix spotify#1118 System property http.nonProxyHosts is processed improperly (spotify#1119)
* Fix spotify#1118 System property http.nonProxyHosts is not processed properly when quotes are used * Fix spotify#1118 System property http.nonProxyHosts is not processed properly when quotes are used Modify unit test to cover changed code * Fix spotify#1118 System property http.nonProxyHosts is not processed properly when quotes are used Modify unit test to cover the case, where proxy.nonProxyHosts property is double quoted. * Fix spotify#1118 System property http.nonProxyHosts is not processed properly when quotes are used Fix checkstyle issues.
1 parent 29cbe7d commit 4f5a275

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/main/java/com/spotify/docker/client/DefaultDockerClient.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175

176176
import org.apache.commons.codec.binary.Base64;
177177
import org.apache.commons.compress.utils.IOUtils;
178+
import org.apache.commons.lang.StringUtils;
178179
import org.apache.http.client.config.RequestConfig;
179180
import org.apache.http.client.methods.CloseableHttpResponse;
180181
import org.apache.http.client.methods.HttpGet;
@@ -497,8 +498,10 @@ private ClientConfig updateProxy(ClientConfig config, Builder builder) {
497498
final String proxyHost = System.getProperty("http.proxyHost");
498499
if (proxyHost != null) {
499500
boolean skipProxy = false;
500-
final String nonProxyHosts = System.getProperty("http.nonProxyHosts");
501+
String nonProxyHosts = System.getProperty("http.nonProxyHosts");
501502
if (nonProxyHosts != null) {
503+
// Remove quotes, if any. Refer to https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html
504+
nonProxyHosts = StringUtils.strip(nonProxyHosts, "\"");
502505
String host = getHost();
503506
for (String nonProxyHost : nonProxyHosts.split("\\|")) {
504507
if (host.matches(toRegExp(nonProxyHost))) {

src/test/java/com/spotify/docker/client/DefaultDockerClientUnitTest.java

+22-6
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
import java.nio.file.Paths;
9494
import java.sql.Date;
9595
import java.time.Instant;
96+
import java.util.Arrays;
9697
import java.util.HashSet;
9798
import java.util.List;
9899
import java.util.Set;
@@ -203,12 +204,27 @@ public void testHostWithNonProxyHost() {
203204
try {
204205
System.setProperty("http.proxyHost", "gmodules.com");
205206
System.setProperty("http.proxyPort", "80");
206-
System.setProperty("http.nonProxyHosts", "127.0.0.1|localhost|192.168.*");
207-
final DefaultDockerClient client = DefaultDockerClient.builder()
208-
.uri("https://192.168.53.103:2375").build();
209-
assertThat((String) client.getClient().getConfiguration()
210-
.getProperty("jersey.config.client.proxy.uri"),
211-
isEmptyOrNullString());
207+
final String nonProxyHostsPropertyValue = "127.0.0.1|localhost|192.168.*";
208+
final List<String> nonProxyHostsPropertyValues = Arrays.asList(
209+
nonProxyHostsPropertyValue, "\"" + nonProxyHostsPropertyValue + "\"");
210+
for (String value : nonProxyHostsPropertyValues) {
211+
System.setProperty("http.nonProxyHosts", value);
212+
final DefaultDockerClient client = DefaultDockerClient.builder()
213+
.uri("https://192.168.53.103:2375").build();
214+
assertThat((String) client.getClient().getConfiguration()
215+
.getProperty("jersey.config.client.proxy.uri"),
216+
isEmptyOrNullString());
217+
final DefaultDockerClient client1 = DefaultDockerClient.builder()
218+
.uri("https://127.0.0.1:2375").build();
219+
assertThat((String) client1.getClient().getConfiguration()
220+
.getProperty("jersey.config.client.proxy.uri"),
221+
isEmptyOrNullString());
222+
final DefaultDockerClient client2 = DefaultDockerClient.builder()
223+
.uri("https://localhost:2375").build();
224+
assertThat((String) client2.getClient().getConfiguration()
225+
.getProperty("jersey.config.client.proxy.uri"),
226+
isEmptyOrNullString());
227+
}
212228
} finally {
213229
System.clearProperty("http.proxyHost");
214230
System.clearProperty("http.proxyPort");

0 commit comments

Comments
 (0)