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

Extract actual Content-Type from the header #1933

Merged
merged 3 commits into from
Nov 25, 2021

Conversation

Kerollmops
Copy link
Member

@Kerollmops Kerollmops commented Nov 24, 2021

This PR should fix #1866 by extracting the actual Content-Type from the header and ignoring everything that follows the first semicolon (;) which, most of the time, means ignoring the charset=utf-8. We use the mime_type method to do so.

Copy link
Member

@irevoire irevoire left a comment

Choose a reason for hiding this comment

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

@MarinPostma I let you merge 👍

Copy link
Contributor

@MarinPostma MarinPostma left a comment

Choose a reason for hiding this comment

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

I would like to use methods provided by actix to handle that :)

Comment on lines 284 to 294
match headers.get(CONTENT_TYPE) {
Some(value) => match value.to_str() {
Ok(content) => Some(
content
.split_once(";")
.map_or(content, |(ct, _)| ct.trim())
.to_string(),
),
Err(_) => Some(format!("{}", value.as_bytes().as_bstr())), // convenient bytes display
},
None => None,
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer that we use this method that is implemented on HttpRequest, and leverage the Mine library, instead of doing this ourselves

Copy link
Member Author

Choose a reason for hiding this comment

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

Wow, didn't see this, that's awesome. The only difference that I see with my function is that it will not try to return a malformed content-type, one that is not utf-8 encoded for example, and we will not be able to return it in the error messages. But, not sure that's very important. Changing my PR to use this method, thank you!

Copy link
Contributor

@MarinPostma MarinPostma left a comment

Choose a reason for hiding this comment

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

Can you update the tests to make use of the server

meilisearch-http/tests/content_type.rs Show resolved Hide resolved
Copy link
Contributor

@MarinPostma MarinPostma left a comment

Choose a reason for hiding this comment

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

look good to me, thank you :)

@MarinPostma MarinPostma merged commit 506349d into new-update-store Nov 25, 2021
@MarinPostma MarinPostma deleted the charset-content-type branch November 25, 2021 10:31
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.

None yet

3 participants