Skip to content

Fixed media type suffix detection #714

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

Merged
merged 2 commits into from
Oct 30, 2023
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
22 changes: 21 additions & 1 deletion lambda-http/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ where
}

for suffix in TEXT_ENCODING_SUFFIXES {
if content_type.ends_with(suffix) {
let mut parts = content_type.trim().split(';');
let mime_type = parts.next().unwrap_or_default();
if mime_type.ends_with(suffix) {
return convert_to_text(self, content_type);
}
}
Expand Down Expand Up @@ -484,6 +486,24 @@ mod tests {
)
}

#[tokio::test]
async fn charset_content_type_header_suffix() {
// Drive the implementation by using `hyper::Body` instead of
// of `aws_lambda_events::encodings::Body`
let response = Response::builder()
.header(CONTENT_TYPE, "application/graphql-response+json; charset=utf-16")
.body(HyperBody::from("000000".as_bytes()))
.expect("unable to build http::Response");
let response = response.into_response().await;
let response = LambdaResponse::from_response(&RequestOrigin::ApiGatewayV2, response);

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

#[tokio::test]
async fn content_headers_unset() {
// Drive the implementation by using `hyper::Body` instead of
Expand Down