Skip to content

Commit 95d9b34

Browse files
authored
fix: silently ignore empty proxy host values (#1099)
1 parent 6099a1c commit 95d9b34

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "7c1e4ec8-d975-498d-affa-ce470d268785",
3+
"type": "bugfix",
4+
"description": "Silently ignore empty/blank proxy host values from environment variables or system properties instead of throwing exceptions",
5+
"issues": [
6+
"smithy-lang/smithy-kotlin#1098"
7+
]
8+
}

runtime/observability/logging-slf4j2/jvm/src/aws/smithy/kotlin/runtime/telemetry/logging/slf4j/Slf4j1xLoggerAdapter.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,18 @@ private class Slf4j1xLogRecordBuilderAdapter(
5757
}
5858

5959
if (kvp.isNotEmpty()) {
60-
val prevCtx = MDC.getCopyOfContextMap()
60+
val prevCtx: Map<String, String>? = MDC.getCopyOfContextMap()
6161
try {
6262
kvp.forEach { (k, v) ->
6363
MDC.put(k, v.toString())
6464
}
6565
logMethod(cause, message)
6666
} finally {
67-
MDC.setContextMap(prevCtx)
67+
if (prevCtx == null) {
68+
MDC.clear()
69+
} else {
70+
MDC.setContextMap(prevCtx)
71+
}
6872
}
6973
} else {
7074
logMethod(cause, message)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ private fun resolveProxyByProperty(provider: PropertyProvider, scheme: Scheme):
5454
val hostPropName = "${scheme.protocolName}.proxyHost"
5555
val hostPortPropName = "${scheme.protocolName}.proxyPort"
5656

57-
val proxyHostProp = provider.getProperty(hostPropName)
58-
val proxyPortProp = provider.getProperty(hostPortPropName)
57+
val proxyHostProp = provider.getProperty(hostPropName).takeUnless { it.isNullOrBlank() }
58+
val proxyPortProp = provider.getProperty(hostPortPropName).takeUnless { it.isNullOrBlank() }
5959

6060
return proxyHostProp?.let { hostName ->
6161
// we don't support connecting to the proxy over TLS, we expect engines would support
@@ -84,7 +84,7 @@ private fun resolveProxyByEnvironment(provider: EnvironmentProvider, scheme: Sch
8484
// lowercase takes precedence: https://about.gitlab.com/blog/2021/01/27/we-need-to-talk-no-proxy/
8585
listOf("${scheme.protocolName.lowercase()}_proxy", "${scheme.protocolName.uppercase()}_PROXY")
8686
.firstNotNullOfOrNull { envVar ->
87-
provider.getenv(envVar)?.let { proxyUrlString ->
87+
provider.getenv(envVar).takeUnless { it.isNullOrBlank() }?.let { proxyUrlString ->
8888
val url = try {
8989
Url.parse(proxyUrlString)
9090
} catch (e: Exception) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ class EnvironmentProxySelectorTest {
4949
private val tests = listOf(
5050
// no props
5151
TestCase(ProxyConfig.Direct),
52+
TestCase(ProxyConfig.Direct, "http://aws.amazon.com", env = mapOf("http_proxy" to "")),
53+
TestCase(ProxyConfig.Direct, "http://aws.amazon.com", env = mapOf("http_proxy" to " ")),
54+
TestCase(ProxyConfig.Direct, "http://aws.amazon.com", props = mapOf("http.proxyHost" to "")),
55+
TestCase(ProxyConfig.Direct, "http://aws.amazon.com", props = mapOf("http.proxyHost" to " ")),
56+
TestCase(ProxyConfig.Direct, env = mapOf("https_proxy" to "")),
57+
TestCase(ProxyConfig.Direct, env = mapOf("https_proxy" to " ")),
58+
TestCase(ProxyConfig.Direct, props = mapOf("https.proxyHost" to "")),
59+
TestCase(ProxyConfig.Direct, props = mapOf("https.proxyHost" to " ")),
5260

5361
// no proxy
5462
TestCase(ProxyConfig.Direct, env = mapOf("no_proxy" to "aws.amazon.com") + httpsProxyEnv),

0 commit comments

Comments
 (0)