Closed yoshuawuyts closed 3 years ago
@Fishrock123 To me it sounds like the features you're suggesting may be out of scope for this PR, even if they seem useful. This PR introduces two typed headers only:
Accept
which is used for content negotiation.Content-Type
which is used to communicate the media type used.Both headers implement the full spec, and in addition to that we also include the content negotiation algorithm to actually make Accept
useful.
Your suggestions around mime-db
likely best be implemented as extensions to our existing http_types::mime::Mime
implementation. Mime
already has some capabilities to infer the type either by reading magic bytes (Mime::sniff
) or by attempting to guess the mime from the file extension (Mime::from_extension
).
We also already have a direct "create a mime from a file" conversion available through (Body::from_file
), which applies both the from_extension
and sniff
methods to determine the file type. Finally Mime
also has a Display
impl that can be used to convert it back out to a string. Though a Mime
-> file extension conversion may indeed be useful.
In short: I think your suggestions are good, but they don't need to block this PR. I've filed separate issues to track what's not been implemented so we can remember to implement them later:
Mime::into_extension
Mime::is_compressible
mime-db
to Rust to enhance our mime extension guessingI don't think we should merge this until the API for content-type is flushed out more.
Ah, well, this and the issues from #274 are what I meant by this - i.e. that we have at least made an effort to think about it.
Adds the
content::{Accept, ContentType}
headers, implementing content negotation for media types. Supersedes https://github.com/http-rs/http-types/pull/269 which only implementedcontent::ContentType
. Ref #99. Thanks!