Add common video, audio, archies and syndication

References:

https://github.com/nginx/nginx/blob/master/conf/mime.types
https://www.iana.org/assignments/media-types/media-types.xhtml
This commit is contained in:
Vic Demuzere 2021-10-31 13:12:32 +01:00
parent 48e783f08f
commit 9ffd9eb921
No known key found for this signature in database
GPG Key ID: 5B9EA1616690CF94
2 changed files with 36 additions and 1 deletions

View File

@ -57,6 +57,8 @@ utf8_mime_const!(CSS, "CSS", "text", "css");
utf8_mime_const!(HTML, "HTML", "text", "html");
utf8_mime_const!(PLAIN, "Plain text", "text", "plain");
utf8_mime_const!(XML, "XML", "application", "xml");
utf8_mime_const!(RSS, "RSS Feed", "application", "rss+xml");
utf8_mime_const!(ATOM, "Atom Feed", "application", "atom+xml");
mime_const!(ANY, "matching anything", "*", "*");
mime_const!(JSON, "JSON", "application", "json");
mime_const!(SSE, "Server Sent Events", "text", "event-stream");
@ -72,6 +74,21 @@ mime_const!(JPEG, "JPEG images", "image", "jpeg");
mime_const!(PNG, "PNG images", "image", "png");
mime_const!(SVG, "SVG", "image", "svg+xml");
mime_const!(WEBP, "WebP images", "image", "webp");
// Audio
// https://www.iana.org/assignments/media-types/media-types.xhtml#audio
mime_const!(MIDI, "MIDI audio", "audio", "midi");
mime_const!(MP3, "MPEG audio layer 3", "audio", "mpeg");
mime_const!(OGG, "Ogg vorbis audio", "audio", "ogg");
mime_const!(OPUS, "Opus audio", "audio", "opus");
mime_const!(M4A, "MPEG audio layer 4", "audio", "mp4");
// Video
// https://www.iana.org/assignments/media-types/media-types.xhtml#video
mime_const!(MP4, "MPEG video layer 4", "video", "mp4");
mime_const!(MPEG, "MPEG video", "video", "mpeg");
mime_const!(WEBM, "WebM video", "video", "webm");
mime_const!(AVI, "Microsoft AVI video", "video", "x-msvideo");
// There are multiple `.ico` mime types known, but `image/x-icon`
// is what most browser use. See:
// https://en.wikipedia.org/wiki/ICO_%28file_format%29#MIME_type
@ -83,3 +100,7 @@ mime_const!(OTF, "OTF", "font", "otf");
mime_const!(TTF, "TTF", "font", "ttf");
mime_const!(WOFF, "WOFF", "font", "woff");
mime_const!(WOFF2, "WOFF2", "font", "woff2");
// Archives
mime_const!(ZIP, "Zip archive", "application", "zip");
mime_const!(SEVENZIP, "7Zip archive", "application", "x-7z-compressed");

View File

@ -53,20 +53,34 @@ impl Mime {
/// Guess the mime type from a file extension
pub fn from_extension(extension: impl AsRef<str>) -> Option<Self> {
match extension.as_ref() {
"7z" => Some(SEVENZIP),
"atom" => Some(ATOM),
"avi" => Some(AVI),
"bin" | "exe" | "dll" | "iso" | "img" => Some(BYTE_STREAM),
"bmp" => Some(BMP),
"css" => Some(CSS),
"html" => Some(HTML),
"ico" => Some(ICO),
"js" | "mjs" | "jsonp" => Some(JAVASCRIPT),
"json" => Some(JSON),
"m4a" => Some(M4A),
"mid" | "midi" | "kar" => Some(MIDI),
"mp3" => Some(MP3),
"mp4" => Some(MP4),
"mpeg" | "mpg" => Some(MPEG),
"ogg" => Some(OGG),
"otf" => Some(OTF),
"svg" => Some(SVG),
"rss" => Some(RSS),
"svg" | "svgz" => Some(SVG),
"ttf" => Some(TTF),
"txt" => Some(PLAIN),
"wasm" => Some(WASM),
"webm" => Some(WEBM),
"webp" => Some(WEBP),
"woff" => Some(WOFF),
"woff2" => Some(WOFF2),
"xml" => Some(XML),
"zip" => Some(ZIP),
_ => None,
}
}