Skip to content

Commit 04774f5

Browse files
authored
fix: respect prefix/suffix wildcards in nonProxyHosts (#1093)
1 parent 14ae580 commit 04774f5

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "cbfc3f67-c8b3-49ad-8e06-0e9bdece01e9",
3+
"type": "bugfix",
4+
"description": "Respect `*` wildcard in `http.nonProxyHosts` when used as prefix or suffix",
5+
"issues": [
6+
"smithy-lang/smithy-kotlin#1092"
7+
]
8+
}

runtime/protocol/http-client/common/src/aws/smithy/kotlin/runtime/http/engine/EnvironmentProxySelector.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ internal data class NonProxyHost(val hostMatch: String, val port: Int? = null) {
105105

106106
val name = url.host.toString()
107107

108+
// handle start/end wildcard cases
109+
if (hostMatch.endsWith("*")) return name.startsWith(hostMatch.removeSuffix("*"))
110+
if (hostMatch.startsWith("*")) return name.endsWith(hostMatch.removePrefix("*"))
111+
108112
if (hostMatch.length > name.length) return false
109113

110114
val match = name.endsWith(hostMatch)

runtime/protocol/http-client/common/test/aws/smithy/kotlin/runtime/http/engine/EnvironmentProxySelectorTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class EnvironmentProxySelectorTest {
4141
"https.proxyPort" to "80",
4242
)
4343
private val httpProxyProps = mapOf("http.proxyHost" to "test.proxy.aws")
44+
private val wildcardPrefixNonProxyProps = mapOf("http.nonProxyHosts" to "*amazon.com")
45+
private val wildcardSuffixNonProxyProps = mapOf("http.nonProxyHosts" to "amazon.co*")
4446

4547
private val expectedProxyConfig = ProxyConfig.Http(Url.parse("http://test.proxy.aws"))
4648

@@ -58,6 +60,20 @@ class EnvironmentProxySelectorTest {
5860
TestCase(ProxyConfig.Direct, props = mapOf("http.nonProxyHosts" to "aws.amazon.com") + httpsProxyProps),
5961
TestCase(ProxyConfig.Direct, props = mapOf("http.nonProxyHosts" to ".amazon.com") + httpsProxyProps),
6062

63+
// no proxy w/ wildcards
64+
65+
TestCase(ProxyConfig.Direct, "https://aws.amazon.com", props = wildcardPrefixNonProxyProps + httpsProxyProps),
66+
TestCase(ProxyConfig.Direct, "https://blamazon.com", props = wildcardPrefixNonProxyProps + httpsProxyProps),
67+
TestCase(ProxyConfig.Direct, "https://amazon.com", props = wildcardPrefixNonProxyProps + httpsProxyProps),
68+
TestCase(expectedProxyConfig, "https://aws.com", props = wildcardPrefixNonProxyProps + httpsProxyProps),
69+
TestCase(expectedProxyConfig, "https://amazon.com.br", props = wildcardPrefixNonProxyProps + httpsProxyProps),
70+
71+
TestCase(ProxyConfig.Direct, "https://amazon.com", props = wildcardSuffixNonProxyProps + httpsProxyProps),
72+
TestCase(ProxyConfig.Direct, "https://amazon.com.br", props = wildcardSuffixNonProxyProps + httpsProxyProps),
73+
TestCase(ProxyConfig.Direct, "https://amazon.co.jp", props = wildcardSuffixNonProxyProps + httpsProxyProps),
74+
TestCase(expectedProxyConfig, "https://aws.amazon.com", props = wildcardSuffixNonProxyProps + httpsProxyProps),
75+
TestCase(expectedProxyConfig, "https://blamazon.com", props = wildcardSuffixNonProxyProps + httpsProxyProps),
76+
6177
// multiple no proxy hosts normalization
6278
TestCase(ProxyConfig.Direct, env = mapOf("no_proxy" to "example.com,.amazon.com") + httpsProxyEnv),
6379
TestCase(ProxyConfig.Direct, props = mapOf("http.noProxyHosts" to "example.com|.amazon.com") + httpsProxyProps),

0 commit comments

Comments
 (0)