Skip to content

Commit 19666b8

Browse files
authored
fix: runtime bug fix (#361)
1 parent 32bc69a commit 19666b8

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

Packages/ClientRuntime/Sources/Networking/Http/HttpContext.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public struct HttpContext: MiddlewareContext {
2626
return attributes.get(key: AttributeKey<ResponseDecoder>(name: "Decoder"))!
2727
}
2828

29-
public func getHost() -> String {
30-
return attributes.get(key: AttributeKey<String>(name: "Host"))!
29+
public func getHost() -> String? {
30+
return attributes.get(key: AttributeKey<String>(name: "Host"))
3131
}
3232

3333
public func getServiceName() -> String {

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/HttpUrlPathMiddleware.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ class HttpUrlPathMiddleware(
9090
resolvedURIComponents.add(it.content)
9191
}
9292
}
93-
writer.write("let hostCustomPath = URL(string: \"http://\\(context.getHost())\")?.path")
93+
9494
val uri = resolvedURIComponents.joinToString(separator = "/", prefix = "/", postfix = "")
9595
writer.write("var urlPath = \"\$L\"", uri)
96-
writer.openBlock("if let hostCustomPath = hostCustomPath, !hostCustomPath.isEmpty {", "}") {
96+
writer.openBlock("if let host = context.getHost(), let hostCustomPath = URL(string: \"http://\\(host)\")?.path, !hostCustomPath.isEmpty {", "}") {
9797
writer.write("urlPath = \"\\(hostCustomPath)\\(urlPath)\"")
9898
}
9999
writer.write("var copiedContext = context")

smithy-swift-codegen/src/test/kotlin/HttpUrlPathMiddlewareTests.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ class HttpUrlPathMiddlewareTests {
2828
guard let label1 = input.label1 else {
2929
return .failure(.client(ClientRuntime.ClientError.pathCreationFailed(("label1 is nil and needs a value for the path of this operation"))))
3030
}
31-
let hostCustomPath = URL(string: "http://\(context.getHost())")?.path
3231
var urlPath = "/smoketest/\(label1.urlPercentEncoding())/foo"
33-
if let hostCustomPath = hostCustomPath, !hostCustomPath.isEmpty {
32+
if let host = context.getHost(), let hostCustomPath = URL(string: "http://\(host)")?.path, !hostCustomPath.isEmpty {
3433
urlPath = "\(hostCustomPath)\(urlPath)"
3534
}
3635
var copiedContext = context

0 commit comments

Comments
 (0)