File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
runtime/protocol/http/common
src/aws/smithy/kotlin/runtime/http/middleware
test/aws/smithy/kotlin/runtime/http/middleware Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,12 @@ class ResolveEndpoint(
3131@InternalApi
3232fun 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
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments