Rename Body::from_file to Body::from_path, add Body::from_file, handle filename-based MIME-type guessing for File objects#318
Rename Body::from_file to Body::from_path, add Body::from_file, handle filename-based MIME-type guessing for File objects#318joshtriplett merged 4 commits intohttp-rs:mainfrom sunfishcode:main
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. |
|
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.
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 <github.downland@aleeas.com>
|
@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_fileout fromBody::from_fileso thatusers who want to use a file opened in a manner other than
File::opencan do so.
In particular, this will help users using
cap_std::fs::Dir::opentoopen files without requiring http-types to have a dependency on
cap_std.