@@ -55,6 +55,66 @@ struct ALBConversionTests {
5555 #expect( httpRequest. headerFields [ HTTPField . Name. userAgent] == " Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " )
5656 }
5757
58+ @Test ( " ALB X-Forwarded-Proto and Host mapping " )
59+ func testALBForwardedHeaders( ) throws {
60+ let albEventWithForwardedHeaders = """
61+ {
62+ " requestContext " : {
63+ " elb " : {
64+ " targetGroupArn " : " arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/lambda-target/50dc6c495c0c9188 "
65+ }
66+ },
67+ " httpMethod " : " GET " ,
68+ " path " : " /stocks/AAPL " ,
69+ " queryStringParameters " : {},
70+ " headers " : {
71+ " Host " : " lambda-alb-123578498.us-east-1.elb.amazonaws.com " ,
72+ " X-Forwarded-Proto " : " https "
73+ },
74+ " body " : " " ,
75+ " isBase64Encoded " : false
76+ }
77+ """
78+
79+ let data = albEventWithForwardedHeaders. data ( using: . utf8) !
80+ let albRequest = try JSONDecoder ( ) . decode ( ALBTargetGroupRequest . self, from: data)
81+
82+ let httpRequest = try albRequest. httpRequest ( )
83+
84+ #expect( httpRequest. scheme == " https " )
85+ #expect( httpRequest. authority == " lambda-alb-123578498.us-east-1.elb.amazonaws.com " )
86+ }
87+
88+ @Test ( " ALB lowercase headers mapping " )
89+ func testALBLowercaseHeaders( ) throws {
90+ let albEventWithLowercaseHeaders = """
91+ {
92+ " requestContext " : {
93+ " elb " : {
94+ " targetGroupArn " : " arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/lambda-target/50dc6c495c0c9188 "
95+ }
96+ },
97+ " httpMethod " : " GET " ,
98+ " path " : " /stocks/AAPL " ,
99+ " queryStringParameters " : {},
100+ " headers " : {
101+ " host " : " lambda-alb-123578498.us-east-1.elb.amazonaws.com " ,
102+ " x-forwarded-proto " : " https "
103+ },
104+ " body " : " " ,
105+ " isBase64Encoded " : false
106+ }
107+ """
108+
109+ let data = albEventWithLowercaseHeaders. data ( using: . utf8) !
110+ let albRequest = try JSONDecoder ( ) . decode ( ALBTargetGroupRequest . self, from: data)
111+
112+ let httpRequest = try albRequest. httpRequest ( )
113+
114+ #expect( httpRequest. scheme == nil )
115+ #expect( httpRequest. authority == nil )
116+ }
117+
58118 @Test ( " HTTPResponse to ALB response conversion " )
59119 func testHTTPResponseToALBResponse( ) throws {
60120 var httpResponse = HTTPResponse ( status: . ok)
0 commit comments