Skip to content

Commit 3ac796c

Browse files
authored
fix: respect hostname immutability in endpoints to disable host prefixing (#612)
1 parent 1b677a6 commit 3ac796c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

runtime/protocol/http/common/src/aws/smithy/kotlin/runtime/http/middleware/ResolveEndpoint.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ class ResolveEndpoint(
3131
@InternalApi
3232
fun setRequestEndpoint(req: SdkHttpRequest, endpoint: Endpoint) {
3333
val hostPrefix = req.context.getOrNull(HttpOperationContext.HostPrefix)
34-
val hostname = if (hostPrefix != null) "${hostPrefix}${endpoint.uri.host}" else endpoint.uri.host
34+
val hostname = if (hostPrefix != null && !endpoint.isHostnameImmutable) {
35+
"$hostPrefix${endpoint.uri.host}"
36+
} else {
37+
endpoint.uri.host
38+
}
39+
3540
req.subject.url.scheme = endpoint.uri.scheme
3641
req.subject.url.host = hostname
3742
req.subject.url.port = endpoint.uri.port

runtime/protocol/http/common/test/aws/smithy/kotlin/runtime/http/middleware/ResolveEndpointTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ class ResolveEndpointTest {
100100
assertEquals("/operation", actual.url.path)
101101
}
102102

103+
@Test
104+
fun testSkipHostPrefixForImmutableHostnames() = runTest {
105+
val op = newTestOperation<Unit, Unit>(HttpRequestBuilder().apply { url.path = "/operation" }, Unit)
106+
val endpoint = Endpoint(uri = Url.parse("http://api.test.com"), isHostnameImmutable = true)
107+
val resolver = EndpointResolver { endpoint }
108+
op.install(ResolveEndpoint(resolver))
109+
op.context[HttpOperationContext.HostPrefix] = "prefix."
110+
111+
op.roundTrip(client, Unit)
112+
val actual = op.context[HttpOperationContext.HttpCallList].first().request
113+
114+
assertEquals("api.test.com", actual.url.host)
115+
assertEquals(Protocol.HTTP, actual.url.scheme)
116+
assertEquals("/operation", actual.url.path)
117+
}
118+
103119
@Test
104120
fun testEndpointPathPrefixWithNonEmptyPath() = runTest {
105121
val op = newTestOperation<Unit, Unit>(HttpRequestBuilder().apply { url.path = "/operation" }, Unit)

0 commit comments

Comments
 (0)