@@ -69,8 +69,8 @@ impl LambdaResponse {
69
69
body,
70
70
is_base64_encoded,
71
71
status_code : status_code as i64 ,
72
- // explicitly empty, as API gateway does not properly merge headers and
73
- // multi-value-headers, resulting in duplicate headers
72
+ // Explicitly empty, as API gateway v1 will merge " headers" and
73
+ // "multi_value_headers" fields together resulting in duplicate response headers.
74
74
headers : HeaderMap :: new ( ) ,
75
75
multi_value_headers : headers,
76
76
} ) ,
@@ -93,21 +93,20 @@ impl LambdaResponse {
93
93
is_base64_encoded,
94
94
status_code : status_code as i64 ,
95
95
cookies,
96
- // explicitly empty, as API gateway does not properly merge headers and
97
- // multi-value-headers, resulting in duplicate headers
98
- headers : HeaderMap :: new ( ) ,
99
- multi_value_headers : headers ,
96
+ // API gateway v2 doesn't have multiValueHeaders field. Duplicate headers are
97
+ // combined with commas and included in the headers field.
98
+ headers : headers ,
99
+ multi_value_headers : HeaderMap :: new ( ) ,
100
100
} )
101
101
}
102
102
#[ cfg( feature = "alb" ) ]
103
103
RequestOrigin :: Alb => LambdaResponse :: Alb ( AlbTargetGroupResponse {
104
104
body,
105
105
status_code : status_code as i64 ,
106
106
is_base64_encoded,
107
- // ALB responses are used for ALB integrations as well as
108
- // Lambda Function URLs. The former uses the `multi_value_headers` field,
109
- // while the later uses the `headers` field. We need to return
110
- // both fields to ensure both integrations work correctly.
107
+ // ALB responses are used for ALB integration, which can be configured to use
108
+ // either headers or multi-value headers field. We need to return both fields to
109
+ // ensure both configuration work correctly.
111
110
headers : headers. clone ( ) ,
112
111
multi_value_headers : headers,
113
112
status_description : Some ( format ! (
@@ -475,7 +474,7 @@ mod tests {
475
474
let json = serde_json:: to_string ( & response) . expect ( "failed to serialize to json" ) ;
476
475
assert_eq ! (
477
476
json,
478
- r#"{"statusCode":200,"headers":{},"multiValueHeaders":{" content-encoding":[ "gzip"] },"body":"MDAwMDAw","isBase64Encoded":true,"cookies":[]}"#
477
+ r#"{"statusCode":200,"headers":{" content-encoding":"gzip"},"multiValueHeaders":{ },"body":"MDAwMDAw","isBase64Encoded":true,"cookies":[]}"#
479
478
)
480
479
}
481
480
@@ -493,7 +492,7 @@ mod tests {
493
492
let json = serde_json:: to_string ( & response) . expect ( "failed to serialize to json" ) ;
494
493
assert_eq ! (
495
494
json,
496
- r#"{"statusCode":200,"headers":{},"multiValueHeaders":{" content-type":[ "application/json"] },"body":"000000","isBase64Encoded":false,"cookies":[]}"#
495
+ r#"{"statusCode":200,"headers":{" content-type":"application/json"},"multiValueHeaders":{ },"body":"000000","isBase64Encoded":false,"cookies":[]}"#
497
496
)
498
497
}
499
498
@@ -511,7 +510,7 @@ mod tests {
511
510
let json = serde_json:: to_string ( & response) . expect ( "failed to serialize to json" ) ;
512
511
assert_eq ! (
513
512
json,
514
- r#"{"statusCode":200,"headers":{},"multiValueHeaders":{" content-type":[ "application/json; charset=utf-16"] },"body":"〰〰〰","isBase64Encoded":false,"cookies":[]}"#
513
+ r#"{"statusCode":200,"headers":{" content-type":"application/json; charset=utf-16"},"multiValueHeaders":{ },"body":"〰〰〰","isBase64Encoded":false,"cookies":[]}"#
515
514
)
516
515
}
517
516
@@ -529,7 +528,7 @@ mod tests {
529
528
let json = serde_json:: to_string ( & response) . expect ( "failed to serialize to json" ) ;
530
529
assert_eq ! (
531
530
json,
532
- r#"{"statusCode":200,"headers":{},"multiValueHeaders":{" content-type":[ "application/graphql-response+json; charset=utf-16"] },"body":"〰〰〰","isBase64Encoded":false,"cookies":[]}"#
531
+ r#"{"statusCode":200,"headers":{" content-type":"application/graphql-response+json; charset=utf-16"},"multiValueHeaders":{ },"body":"〰〰〰","isBase64Encoded":false,"cookies":[]}"#
533
532
)
534
533
}
535
534
0 commit comments