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

Fixed media type suffix detection #714

merged 2 commits into from
Oct 30, 2023

Conversation

bnusunny
Copy link
Contributor

@bnusunny bnusunny commented Oct 29, 2023

Issue #, if available:

Related to awslabs/aws-lambda-web-adapter#265

Description of changes:

Content-Type value contains media type and optional parameters (such as charset, boundary, filename, and Content-Disposition). So we need to extract the media type part and compare its suffix. Otherwise, the response body will be treated as binary.

By submitting this pull request

  • I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • I confirm that I've made a best effort attempt to update all relevant documentation.

Content-Type value contains media type and optional parameters (such as charset, boundary, filename, and Content-Disposition). So we need to extract the media type part and compare its suffix.
@bnusunny bnusunny requested a review from calavera October 29, 2023 05:44
let parts = content_type.trim().split(';');

let mut media_type = String::new();
for part in parts {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure that the mime type is always the first value if you split the header value with ;. You might not need to iterate over all the parts, you can take the first element.

As far as I know the value's syntax is MIMETYPE; PARAMETERS

Copy link
Contributor

Choose a reason for hiding this comment

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

If that's not the only valid syntax, we should test other possible values.

Copy link
Contributor Author

@bnusunny bnusunny Oct 30, 2023

Choose a reason for hiding this comment

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

Right. I simplified the code to take the first element.

@bnusunny bnusunny merged commit 3e195f6 into main Oct 30, 2023
@bnusunny bnusunny deleted the fix-media-type-detection branch October 30, 2023 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants