Skip to content

Commit d78d8a0

Browse files
authored
Fix bug in using nonProxyHosts with CRT http/s3 clients (#6511)
* WIP - TEMPORARY testing of the crt no_proxy_hosts * Set the noProxyHosts on CRTs HttpProxyOptions * Fix spotbugs
1 parent 5d8751e commit d78d8a0

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "",
5+
"description": "Correctly use noProxyHosts from CrtProxyConfiguration."
6+
}

core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtConfigurationUtils.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515

1616
package software.amazon.awssdk.crtcore;
1717

18-
import static software.amazon.awssdk.utils.StringUtils.lowerCase;
19-
20-
import java.util.Objects;
2118
import java.util.Optional;
22-
import java.util.Set;
2319
import software.amazon.awssdk.annotations.SdkProtectedApi;
2420
import software.amazon.awssdk.crt.http.HttpMonitoringOptions;
2521
import software.amazon.awssdk.crt.http.HttpProxyOptions;
@@ -37,13 +33,14 @@ public static Optional<HttpProxyOptions> resolveProxy(CrtProxyConfiguration prox
3733
if (proxyConfiguration == null) {
3834
return Optional.empty();
3935
}
40-
if (doesTargetMatchNonProxyHosts(proxyConfiguration.host(), proxyConfiguration.nonProxyHosts())) {
41-
return Optional.empty();
42-
}
36+
4337
HttpProxyOptions clientProxyOptions = new HttpProxyOptions();
4438

4539
clientProxyOptions.setHost(proxyConfiguration.host());
4640
clientProxyOptions.setPort(proxyConfiguration.port());
41+
if (!proxyConfiguration.nonProxyHosts().isEmpty()) {
42+
clientProxyOptions.setNoProxyHosts(String.join(",", proxyConfiguration.nonProxyHosts()));
43+
}
4744

4845
if ("https".equalsIgnoreCase(proxyConfiguration.scheme())) {
4946
clientProxyOptions.setTlsContext(tlsContext);
@@ -60,15 +57,6 @@ public static Optional<HttpProxyOptions> resolveProxy(CrtProxyConfiguration prox
6057
return Optional.of(clientProxyOptions);
6158
}
6259

63-
private static boolean doesTargetMatchNonProxyHosts(String target, Set<String> hostPatterns) {
64-
return Optional.ofNullable(hostPatterns)
65-
.map(patterns ->
66-
patterns.stream()
67-
.filter(Objects::nonNull)
68-
.anyMatch(pattern -> target != null && lowerCase(target).matches(pattern)))
69-
.orElse(false);
70-
}
71-
7260
public static Optional<HttpMonitoringOptions> resolveHttpMonitoringOptions(CrtConnectionHealthConfiguration config) {
7361
if (config == null) {
7462
return Optional.empty();

core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtProxyConfiguration.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,18 @@ public interface Builder {
281281

282282
/**
283283
* Configure the hosts that the client is allowed to access without going through the proxy.
284+
* The only wildcard available is a single "*" character, which matches all hosts.
285+
* IP addresses specified to this option can be provided using CIDR notation: an appended slash and number
286+
* specifies the number of "network bits" out of the address to use in the comparison.
284287
*/
285288
Builder nonProxyHosts(Set<String> nonProxyHosts);
286289

287290

288291
/**
289292
* Add a host that the client is allowed to access without going through the proxy.
293+
* The only wildcard available is a single "*" character, which matches all hosts.
294+
* IP addresses specified to this option can be provided using CIDR notation: an appended slash and number
295+
* specifies the number of "network bits" out of the address to use in the comparison.
290296
*/
291297
Builder addNonProxyHost(String nonProxyHost);
292298

core/crt-core/src/test/java/software/amazon/awssdk/crtcore/CrtConnectionUtilsTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ void resolveProxy_emptyProxy_shouldReturnEmpty() {
5858
assertThat(CrtConfigurationUtils.resolveProxy(null, tlsContext)).isEmpty();
5959
}
6060

61-
@ParameterizedTest
62-
@ValueSource(strings = {".*?.2.3.4", "1.*?.3.4", ".*?"})
63-
void resolveProxy_withSingleNonProxyHostsWidCards_shouldReturnEmpty(String nonProxyHost) {
61+
@Test
62+
void resolveProxy_nonProxyHosts_setAsCommaSeperatedString() {
6463
TlsContext tlsContext = Mockito.mock(TlsContext.class);
6564
CrtProxyConfiguration configuration = new TestProxy.Builder().host("1.2.3.4")
6665
.port(123)
6766
.scheme("https")
6867
.password("bar")
6968
.username("foo")
70-
.nonProxyHosts(Stream.of(nonProxyHost,"someRandom")
71-
.collect(Collectors.toSet()))
69+
.addNonProxyHost("host1")
70+
.addNonProxyHost("host2")
7271
.build();
73-
assertThat(CrtConfigurationUtils.resolveProxy(configuration, tlsContext)).isEmpty();
72+
assertThat(CrtConfigurationUtils.resolveProxy(configuration, tlsContext).get().getNoProxyHosts())
73+
.isEqualTo("host1,host2");
7474
}
7575

7676

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
<rxjava3.version>3.1.5</rxjava3.version>
130130
<commons-codec.verion>1.17.1</commons-codec.verion>
131131
<jmh.version>1.37</jmh.version>
132-
<awscrt.version>0.38.9</awscrt.version>
132+
<awscrt.version>0.39.4</awscrt.version>
133133

134134
<!--Test dependencies -->
135135
<junit5.version>5.10.0</junit5.version>

0 commit comments

Comments
 (0)