Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return correct header keys for each integration #877

Merged
merged 1 commit into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions lambda-http/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ impl LambdaResponse {
body,
is_base64_encoded,
status_code: status_code as i64,
// explicitly empty, as API gateway does not properly merge headers and
// multi-value-headers, resulting in duplicate headers
// Explicitly empty, as API gateway v1 will merge "headers" and
// "multi_value_headers" fields together resulting in duplicate response headers.
headers: HeaderMap::new(),
multi_value_headers: headers,
}),
Expand All @@ -93,21 +93,20 @@ impl LambdaResponse {
is_base64_encoded,
status_code: status_code as i64,
cookies,
// explicitly empty, as API gateway does not properly merge headers and
// multi-value-headers, resulting in duplicate headers
headers: HeaderMap::new(),
multi_value_headers: headers,
// API gateway v2 doesn't have "multi_value_headers" field. Duplicate headers
// are combined with commas and included in the headers field.
headers,
multi_value_headers: HeaderMap::new(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field should probably be removed from ApiGatewayV2httpResponse struct but for simplicity of this fix I'm going to leave it there for now.

})
}
#[cfg(feature = "alb")]
RequestOrigin::Alb => LambdaResponse::Alb(AlbTargetGroupResponse {
body,
status_code: status_code as i64,
is_base64_encoded,
// ALB responses are used for ALB integrations as well as
// Lambda Function URLs. The former uses the `multi_value_headers` field,
// while the later uses the `headers` field. We need to return
// both fields to ensure both integrations work correctly.
// ALB responses are used for ALB integration, which can be configured to use
// either "headers" or "multi_value_headers" field. We need to return both fields
// to ensure both configuration work correctly.
headers: headers.clone(),
multi_value_headers: headers,
status_description: Some(format!(
Expand All @@ -121,8 +120,8 @@ impl LambdaResponse {
body,
is_base64_encoded,
status_code: status_code as i64,
// explicitly empty, as API gateway does not properly merge headers and
// multi-value-headers, resulting in duplicate headers
// Explicitly empty, as API gateway v1 will merge "headers" and
// "multi_value_headers" fields together resulting in duplicate response headers.
headers: HeaderMap::new(),
multi_value_headers: headers,
}),
Expand Down Expand Up @@ -475,7 +474,7 @@ mod tests {
let json = serde_json::to_string(&response).expect("failed to serialize to json");
assert_eq!(
json,
r#"{"statusCode":200,"headers":{},"multiValueHeaders":{"content-encoding":["gzip"]},"body":"MDAwMDAw","isBase64Encoded":true,"cookies":[]}"#
r#"{"statusCode":200,"headers":{"content-encoding":"gzip"},"multiValueHeaders":{},"body":"MDAwMDAw","isBase64Encoded":true,"cookies":[]}"#
)
}

Expand All @@ -493,7 +492,7 @@ mod tests {
let json = serde_json::to_string(&response).expect("failed to serialize to json");
assert_eq!(
json,
r#"{"statusCode":200,"headers":{},"multiValueHeaders":{"content-type":["application/json"]},"body":"000000","isBase64Encoded":false,"cookies":[]}"#
r#"{"statusCode":200,"headers":{"content-type":"application/json"},"multiValueHeaders":{},"body":"000000","isBase64Encoded":false,"cookies":[]}"#
)
}

Expand All @@ -511,7 +510,7 @@ mod tests {
let json = serde_json::to_string(&response).expect("failed to serialize to json");
assert_eq!(
json,
r#"{"statusCode":200,"headers":{},"multiValueHeaders":{"content-type":["application/json; charset=utf-16"]},"body":"〰〰〰","isBase64Encoded":false,"cookies":[]}"#
r#"{"statusCode":200,"headers":{"content-type":"application/json; charset=utf-16"},"multiValueHeaders":{},"body":"〰〰〰","isBase64Encoded":false,"cookies":[]}"#
)
}

Expand All @@ -529,7 +528,7 @@ mod tests {
let json = serde_json::to_string(&response).expect("failed to serialize to json");
assert_eq!(
json,
r#"{"statusCode":200,"headers":{},"multiValueHeaders":{"content-type":["application/graphql-response+json; charset=utf-16"]},"body":"〰〰〰","isBase64Encoded":false,"cookies":[]}"#
r#"{"statusCode":200,"headers":{"content-type":"application/graphql-response+json; charset=utf-16"},"multiValueHeaders":{},"body":"〰〰〰","isBase64Encoded":false,"cookies":[]}"#
)
}

Expand Down
Loading