From ebd469376f904c1165834f351c6f3cafc9e64027 Mon Sep 17 00:00:00 2001 From: Alex Woods Date: Thu, 16 Oct 2025 09:12:23 -0700 Subject: [PATCH 1/3] WIP - TEMPORARY testing of the crt no_proxy_hosts --- core/crt-core/pom.xml | 2 +- .../awssdk/crtcore/CrtConfigurationUtils.java | 19 +++---------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/core/crt-core/pom.xml b/core/crt-core/pom.xml index c2b062303577..cc427482238c 100644 --- a/core/crt-core/pom.xml +++ b/core/crt-core/pom.xml @@ -43,7 +43,7 @@ software.amazon.awssdk.crt aws-crt - ${awscrt.version} + 1.0.0-SNAPSHOT true diff --git a/core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtConfigurationUtils.java b/core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtConfigurationUtils.java index 6d31d621a1ca..6c4ff475c422 100644 --- a/core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtConfigurationUtils.java +++ b/core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtConfigurationUtils.java @@ -15,11 +15,7 @@ package software.amazon.awssdk.crtcore; -import static software.amazon.awssdk.utils.StringUtils.lowerCase; - -import java.util.Objects; import java.util.Optional; -import java.util.Set; import software.amazon.awssdk.annotations.SdkProtectedApi; import software.amazon.awssdk.crt.http.HttpMonitoringOptions; import software.amazon.awssdk.crt.http.HttpProxyOptions; @@ -37,13 +33,13 @@ public static Optional resolveProxy(CrtProxyConfiguration prox if (proxyConfiguration == null) { return Optional.empty(); } - if (doesTargetMatchNonProxyHosts(proxyConfiguration.host(), proxyConfiguration.nonProxyHosts())) { - return Optional.empty(); - } + HttpProxyOptions clientProxyOptions = new HttpProxyOptions(); clientProxyOptions.setHost(proxyConfiguration.host()); clientProxyOptions.setPort(proxyConfiguration.port()); + // TODO: Validate these + clientProxyOptions.setNoProxyHosts(String.join(",", proxyConfiguration.nonProxyHosts())); if ("https".equalsIgnoreCase(proxyConfiguration.scheme())) { clientProxyOptions.setTlsContext(tlsContext); @@ -60,15 +56,6 @@ public static Optional resolveProxy(CrtProxyConfiguration prox return Optional.of(clientProxyOptions); } - private static boolean doesTargetMatchNonProxyHosts(String target, Set hostPatterns) { - return Optional.ofNullable(hostPatterns) - .map(patterns -> - patterns.stream() - .filter(Objects::nonNull) - .anyMatch(pattern -> target != null && lowerCase(target).matches(pattern))) - .orElse(false); - } - public static Optional resolveHttpMonitoringOptions(CrtConnectionHealthConfiguration config) { if (config == null) { return Optional.empty(); From 740d5ac4f0ebee3ea722bbf5767fab6c791aeced Mon Sep 17 00:00:00 2001 From: Alex Woods Date: Thu, 23 Oct 2025 12:15:45 -0700 Subject: [PATCH 2/3] Set the noProxyHosts on CRTs HttpProxyOptions --- .../next-release/bugfix-AWSSDKforJavav2-5972f21.json | 6 ++++++ core/crt-core/pom.xml | 4 ++-- .../amazon/awssdk/crtcore/CrtConfigurationUtils.java | 5 +++-- .../amazon/awssdk/crtcore/CrtProxyConfiguration.java | 6 ++++++ .../awssdk/crtcore/CrtConnectionUtilsTest.java | 12 ++++++------ pom.xml | 2 +- 6 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 .changes/next-release/bugfix-AWSSDKforJavav2-5972f21.json diff --git a/.changes/next-release/bugfix-AWSSDKforJavav2-5972f21.json b/.changes/next-release/bugfix-AWSSDKforJavav2-5972f21.json new file mode 100644 index 000000000000..a413976e1bb1 --- /dev/null +++ b/.changes/next-release/bugfix-AWSSDKforJavav2-5972f21.json @@ -0,0 +1,6 @@ +{ + "type": "bugfix", + "category": "AWS SDK for Java v2", + "contributor": "", + "description": "Correctly use noProxyHosts from CrtProxyConfiguration." +} diff --git a/core/crt-core/pom.xml b/core/crt-core/pom.xml index cc427482238c..3ec07f263745 100644 --- a/core/crt-core/pom.xml +++ b/core/crt-core/pom.xml @@ -21,7 +21,7 @@ software.amazon.awssdk core - 2.35.6-SNAPSHOT + 2.35.11-SNAPSHOT crt-core @@ -43,7 +43,7 @@ software.amazon.awssdk.crt aws-crt - 1.0.0-SNAPSHOT + ${awscrt.version} true diff --git a/core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtConfigurationUtils.java b/core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtConfigurationUtils.java index 6c4ff475c422..a3fac4ab6568 100644 --- a/core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtConfigurationUtils.java +++ b/core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtConfigurationUtils.java @@ -38,8 +38,9 @@ public static Optional resolveProxy(CrtProxyConfiguration prox clientProxyOptions.setHost(proxyConfiguration.host()); clientProxyOptions.setPort(proxyConfiguration.port()); - // TODO: Validate these - clientProxyOptions.setNoProxyHosts(String.join(",", proxyConfiguration.nonProxyHosts())); + if (proxyConfiguration.nonProxyHosts() != null && !proxyConfiguration.nonProxyHosts().isEmpty()) { + clientProxyOptions.setNoProxyHosts(String.join(",", proxyConfiguration.nonProxyHosts())); + } if ("https".equalsIgnoreCase(proxyConfiguration.scheme())) { clientProxyOptions.setTlsContext(tlsContext); diff --git a/core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtProxyConfiguration.java b/core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtProxyConfiguration.java index 42f1dda97975..05969c913a52 100644 --- a/core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtProxyConfiguration.java +++ b/core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtProxyConfiguration.java @@ -281,12 +281,18 @@ public interface Builder { /** * Configure the hosts that the client is allowed to access without going through the proxy. + * The only wildcard available is a single "*" character, which matches all hosts. + * IP addresses specified to this option can be provided using CIDR notation: an appended slash and number + * specifies the number of "network bits" out of the address to use in the comparison. */ Builder nonProxyHosts(Set nonProxyHosts); /** * Add a host that the client is allowed to access without going through the proxy. + * The only wildcard available is a single "*" character, which matches all hosts. + * IP addresses specified to this option can be provided using CIDR notation: an appended slash and number + * specifies the number of "network bits" out of the address to use in the comparison. */ Builder addNonProxyHost(String nonProxyHost); diff --git a/core/crt-core/src/test/java/software/amazon/awssdk/crtcore/CrtConnectionUtilsTest.java b/core/crt-core/src/test/java/software/amazon/awssdk/crtcore/CrtConnectionUtilsTest.java index 2c6bc24cc48a..08ca7c119c85 100644 --- a/core/crt-core/src/test/java/software/amazon/awssdk/crtcore/CrtConnectionUtilsTest.java +++ b/core/crt-core/src/test/java/software/amazon/awssdk/crtcore/CrtConnectionUtilsTest.java @@ -58,19 +58,19 @@ void resolveProxy_emptyProxy_shouldReturnEmpty() { assertThat(CrtConfigurationUtils.resolveProxy(null, tlsContext)).isEmpty(); } - @ParameterizedTest - @ValueSource(strings = {".*?.2.3.4", "1.*?.3.4", ".*?"}) - void resolveProxy_withSingleNonProxyHostsWidCards_shouldReturnEmpty(String nonProxyHost) { + @Test + void resolveProxy_nonProxyHosts_setAsCommaSeperatedString() { TlsContext tlsContext = Mockito.mock(TlsContext.class); CrtProxyConfiguration configuration = new TestProxy.Builder().host("1.2.3.4") .port(123) .scheme("https") .password("bar") .username("foo") - .nonProxyHosts(Stream.of(nonProxyHost,"someRandom") - .collect(Collectors.toSet())) + .addNonProxyHost("host1") + .addNonProxyHost("host2") .build(); - assertThat(CrtConfigurationUtils.resolveProxy(configuration, tlsContext)).isEmpty(); + assertThat(CrtConfigurationUtils.resolveProxy(configuration, tlsContext).get().getNoProxyHosts()) + .isEqualTo("host1,host2"); } diff --git a/pom.xml b/pom.xml index a0b09945bbf7..d7a6239a95c9 100644 --- a/pom.xml +++ b/pom.xml @@ -129,7 +129,7 @@ 3.1.5 1.17.1 1.37 - 0.38.9 + 0.39.4 5.10.0 From 71ada182cd13e21b60a23ec498fec3c0fbc63e97 Mon Sep 17 00:00:00 2001 From: Alex Woods Date: Thu, 23 Oct 2025 12:50:10 -0700 Subject: [PATCH 3/3] Fix spotbugs --- .../software/amazon/awssdk/crtcore/CrtConfigurationUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtConfigurationUtils.java b/core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtConfigurationUtils.java index a3fac4ab6568..b9a08ac01903 100644 --- a/core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtConfigurationUtils.java +++ b/core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtConfigurationUtils.java @@ -38,7 +38,7 @@ public static Optional resolveProxy(CrtProxyConfiguration prox clientProxyOptions.setHost(proxyConfiguration.host()); clientProxyOptions.setPort(proxyConfiguration.port()); - if (proxyConfiguration.nonProxyHosts() != null && !proxyConfiguration.nonProxyHosts().isEmpty()) { + if (!proxyConfiguration.nonProxyHosts().isEmpty()) { clientProxyOptions.setNoProxyHosts(String.join(",", proxyConfiguration.nonProxyHosts())); }