@@ -76,21 +76,20 @@ fn into_api_gateway_v2_request(ag: ApiGatewayV2httpRequest) -> http::Request<Bod
76
76
77
77
let builder = http:: Request :: builder ( )
78
78
. uri ( {
79
- let scheme = ag
80
- . headers
81
- . get ( x_forwarded_proto ( ) )
82
- . and_then ( |s| s. to_str ( ) . ok ( ) )
83
- . unwrap_or ( "https" ) ;
84
- let host = ag
85
- . headers
86
- . get ( http:: header:: HOST )
87
- . and_then ( |s| s. to_str ( ) . ok ( ) )
88
- . or ( ag. request_context . domain_name . as_deref ( ) )
89
- . unwrap_or_default ( ) ;
90
-
79
+ let host = ag. headers . get ( http:: header:: HOST ) . and_then ( |s| s. to_str ( ) . ok ( ) ) ;
91
80
let path = apigw_path_with_stage ( & ag. request_context . stage , & raw_path) ;
92
- let mut url = format ! ( "{}://{}{}" , scheme, host, path) ;
93
81
82
+ let mut url = match host {
83
+ None => path,
84
+ Some ( host) => {
85
+ let scheme = ag
86
+ . headers
87
+ . get ( x_forwarded_proto ( ) )
88
+ . and_then ( |s| s. to_str ( ) . ok ( ) )
89
+ . unwrap_or ( "https" ) ;
90
+ format ! ( "{}://{}{}" , scheme, host, path)
91
+ }
92
+ } ;
94
93
if let Some ( query) = ag. raw_query_string {
95
94
url. push ( '?' ) ;
96
95
url. push_str ( & query) ;
@@ -199,18 +198,20 @@ fn into_alb_request(alb: AlbTargetGroupRequest) -> http::Request<Body> {
199
198
200
199
let builder = http:: Request :: builder ( )
201
200
. uri ( {
202
- let scheme = alb
203
- . headers
204
- . get ( x_forwarded_proto ( ) )
205
- . and_then ( |s| s. to_str ( ) . ok ( ) )
206
- . unwrap_or ( "https" ) ;
207
- let host = alb
208
- . headers
209
- . get ( http:: header:: HOST )
210
- . and_then ( |s| s. to_str ( ) . ok ( ) )
211
- . unwrap_or_default ( ) ;
212
-
213
- let mut url = format ! ( "{}://{}{}" , scheme, host, & raw_path) ;
201
+ let host = alb. headers . get ( http:: header:: HOST ) . and_then ( |s| s. to_str ( ) . ok ( ) ) ;
202
+
203
+ let mut url = match host {
204
+ None => raw_path. clone ( ) ,
205
+ Some ( host) => {
206
+ let scheme = alb
207
+ . headers
208
+ . get ( x_forwarded_proto ( ) )
209
+ . and_then ( |s| s. to_str ( ) . ok ( ) )
210
+ . unwrap_or ( "https" ) ;
211
+ format ! ( "{}://{}{}" , scheme, host, & raw_path)
212
+ }
213
+ } ;
214
+
214
215
if !alb. multi_value_query_string_parameters . is_empty ( ) {
215
216
url. push ( '?' ) ;
216
217
url. push_str ( & alb. multi_value_query_string_parameters . to_query_string ( ) ) ;
@@ -625,4 +626,20 @@ mod tests {
625
626
assert_eq ! ( req. method( ) , "GET" ) ;
626
627
assert_eq ! ( req. uri( ) , "/test/test/hello?name=me" ) ;
627
628
}
629
+
630
+ #[ test]
631
+ fn deserialize_alb_no_host ( ) {
632
+ // generated from ALB health checks
633
+ let input = include_str ! ( "../tests/data/alb_no_host.json" ) ;
634
+ let result = from_str ( input) ;
635
+ assert ! (
636
+ result. is_ok( ) ,
637
+ "event was not parsed as expected {:?} given {}" ,
638
+ result,
639
+ input
640
+ ) ;
641
+ let req = result. expect ( "failed to parse request" ) ;
642
+ assert_eq ! ( req. method( ) , "GET" ) ;
643
+ assert_eq ! ( req. uri( ) , "/v1/health/" ) ;
644
+ }
628
645
}
0 commit comments