Skip to content

Commit b3844f7

Browse files
committed
allow for mixed case header names
1 parent b6b6a9a commit b3844f7

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

Sources/EventSource/ALB/ALBTargetGroup+HTTPRequest.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ extension ALBTargetGroupRequest {
2020

2121
/// Return an `HTTPRequest` for this `ALBTargetGroupRequest`
2222
public func httpRequest() throws -> HTTPRequest {
23-
HTTPRequest(
23+
let headers = self.headers ?? [:]
24+
let scheme = headers.first { $0.key.lowercased() == "x-forwarded-proto" }?.value
25+
let authority = headers.first { $0.key.lowercased() == "host" }?.value
26+
27+
return HTTPRequest(
2428
method: self.httpMethod,
25-
scheme: self.headers?["X-Forwarded-Proto"],
26-
authority: self.headers?["Host"],
29+
scheme: scheme,
30+
authority: authority,
2731
path: self.path,
28-
headerFields: self.headers?.httpFields() ?? [:]
32+
headerFields: headers.httpFields()
2933
)
3034
}
3135
}

Tests/OpenAPILambdaTests/ALBConversionTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ struct ALBConversionTests {
111111

112112
let httpRequest = try albRequest.httpRequest()
113113

114-
#expect(httpRequest.scheme == nil)
115-
#expect(httpRequest.authority == nil)
114+
#expect(httpRequest.scheme == "https")
115+
#expect(httpRequest.authority == "lambda-alb-123578498.us-east-1.elb.amazonaws.com")
116116
}
117117

118118
@Test("HTTPResponse to ALB response conversion")

0 commit comments

Comments
 (0)