-
Notifications
You must be signed in to change notification settings - Fork 321
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
use http_types::mime instead of the mime crate #536
Conversation
3507a3a
to
8d13df2
Compare
src/fs/serve_dir.rs
Outdated
@@ -70,7 +71,7 @@ impl<State> Endpoint<State> for ServeDir { | |||
res.set_body(body); | |||
|
|||
if let Some(content_type) = mime_guess::from_path(&file_path).first() { | |||
res = res.set_mime(content_type); | |||
res = res.set_mime(content_type.to_string().parse::<Mime>().unwrap()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not very nice, should http_types::HeaderValue
have an into for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this code is temporary and will be replaced by the mime sniffing stuff in http_types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is converting from a mime::Mime to a http_types::Mime, and I think the goal is for neither tide nor http_types to have a dep on the mime crate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http-types Body now has a from_file
constructor that applies the inference. Could as maybe use that here?
The trickiest part I see is checking the error type so that we can set the right status codes, but that should be possible through downcasting.
That way we can get rid of the mime
dep effective immediately!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 5000e1c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably ensure in http-types that we return the right status codes here — but that's worth filing an issue for. Otherwise this looks good!
Fix the use of the mime crate in the graphql example (brought up by #534), which was a mistake. This pr removes dependence on the mime crate entirely, in preference to http_types::Mime
This pr also allows set_mime to accept an Into, and calls through to the http_types::Response::set_content_type