1 unstable release
0.1.0 | Aug 26, 2022 |
---|
#16 in #media-type
17KB
371 lines
A work in progress Media-Type parsing library
Allows for relatively easy interpreting of Content-Type headers and "fuzzy" matching of subtypes
use fuzzy_mime::BorrowedMediaType;
let media_type = BorrowedMediaType::parse("application/json;charset=utf-8").unwrap();
assert!(media_type.matches("application/json"))
lib.rs
:
Simple Media-Type library that focuses on ease of use Media Types are
used to specify the media type and subtype of data in the body of a message and to fully specify the native representation (canonical form) of such data -- Based on RFC-7231 and RFC-2046 and originally developed from RFC-1049 Media types specify the contents of a message or body, but can be more specific than your code requires Any media type that is less specific should match.
use fuzzy_mime::BorrowedMediaType;
let media_type = BorrowedMediaType::parse("application/json;charset=utf-8").unwrap();
assert!(media_type.matches("application/json"))
Mime types which are more specific will fail
use fuzzy_mime::BorrowedMediaType;
let media_type = BorrowedMediaType::parse("application/json").unwrap();
assert!(media_type.matches("application/json;charset=utf-8"))
Structured types that extend another also work
use fuzzy_mime::BorrowedMediaType;
let media_type = BorrowedMediaType::parse("application/vnd.docker.distribution.manifest.v1+json").unwrap();
assert!(media_type.matches("application/json"))