-
Notifications
You must be signed in to change notification settings - Fork 84
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
Rename Body::from_file to Body::from_path, add Body::from_file, handle filename-based MIME-type guessing for File objects #318
Conversation
The clippy error doesn't look related to this patch. |
I just noticed that this PR is very similar to another existing PR, #296. The main difference is that this PR's Also, this PR uses different names: |
I prefer #296. |
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.
As per my former comment
I'm ok with Concerning the mime type, there are some situations where |
I've now updated this PR to use the |
If I'm not mistaken this appears to be a breaking change. I'm okay with merging this, but we'll have to do this as part of our 3.0 effort. Luckily that should be kicking off tomorrow (last pre-3.0 http-types release today), so we'll be able to merge this soon! (: |
/// to `application/octet-stream`. | ||
/// | ||
/// The path here is only used to provide an extension for guessing the Mime | ||
/// type, and may be empty if the path is unknown. |
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 I'd prefer Option<&std::path::Path>
rather than requiring the caller to construct and pass an empty Path
.
Reading this change and #296, it looks like the main difference is that #296 only tries to guess the MIME type in I made one comment above about the path argument (using I personally think the common case of
Personally, I suspect it won't be especially common to pass an already-open Does that seem reasonable to you, @sunfishcode? |
Body::from_open_file
constructor.This splits a `Body::from_open_file` out from `Body::from_file` so that users who want to use a file opened in a manner other than `File::open` can do so. In particular, this will help users using [`cap_std::fs::Dir::open`] to open files without requiring http-types to have a dependency on `cap_std`. [`cap_std::fs::Dir::open`]: https://docs.rs/cap-std/latest/cap_std/fs/struct.Dir.html#method.open Co-authored-by: brightly-salty <[email protected]>
@joshtriplett The The doc comment wasn't copied from #296; it's likely that we both copied the comment from the pre-existing |
Implemented via subsequent changes.
@sunfishcode wrote:
Fair enough.
Ah, makes sense.
Thank you for your graceful handling of this. I know that it's frustrating when work gets duplicated. Merging. |
This splits a
Body::from_open_file
out fromBody::from_file
so thatusers who want to use a file opened in a manner other than
File::open
can do so.
In particular, this will help users using
cap_std::fs::Dir::open
toopen files without requiring http-types to have a dependency on
cap_std
.