Skip to content

Commit 48e783f

Browse files
committed
Add font and additional image mime types
1 parent 7d7323a commit 48e783f

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/mime/constants.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,27 @@ utf8_mime_const!(PLAIN, "Plain text", "text", "plain");
5959
utf8_mime_const!(XML, "XML", "application", "xml");
6060
mime_const!(ANY, "matching anything", "*", "*");
6161
mime_const!(JSON, "JSON", "application", "json");
62-
mime_const!(SVG, "SVG", "image", "svg+xml");
63-
mime_const!(PNG, "PNG images", "image", "png");
64-
mime_const!(JPEG, "JPEG images", "image", "jpeg");
6562
mime_const!(SSE, "Server Sent Events", "text", "event-stream");
6663
mime_const!(BYTE_STREAM, "byte streams", "application", "octet-stream");
6764
mime_const!(FORM, "forms", "application", "x-www-form-urlencoded");
6865
mime_const!(MULTIPART_FORM, "multipart forms", "multipart", "form-data");
6966
mime_const!(WASM, "webassembly", "application", "wasm");
67+
68+
// Images
69+
// https://www.iana.org/assignments/media-types/media-types.xhtml#image
70+
mime_const!(BMP, "BMP images", "image", "bmp");
71+
mime_const!(JPEG, "JPEG images", "image", "jpeg");
72+
mime_const!(PNG, "PNG images", "image", "png");
73+
mime_const!(SVG, "SVG", "image", "svg+xml");
74+
mime_const!(WEBP, "WebP images", "image", "webp");
7075
// There are multiple `.ico` mime types known, but `image/x-icon`
7176
// is what most browser use. See:
7277
// https://en.wikipedia.org/wiki/ICO_%28file_format%29#MIME_type
7378
mime_const!(ICO, "ICO icons", "image", "x-icon");
79+
80+
// Fonts
81+
// https://www.iana.org/assignments/media-types/media-types.xhtml#font
82+
mime_const!(OTF, "OTF", "font", "otf");
83+
mime_const!(TTF, "TTF", "font", "ttf");
84+
mime_const!(WOFF, "WOFF", "font", "woff");
85+
mime_const!(WOFF2, "WOFF2", "font", "woff2");

src/mime/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,19 @@ impl Mime {
5353
/// Guess the mime type from a file extension
5454
pub fn from_extension(extension: impl AsRef<str>) -> Option<Self> {
5555
match extension.as_ref() {
56+
"bmp" => Some(BMP),
57+
"css" => Some(CSS),
5658
"html" => Some(HTML),
59+
"ico" => Some(ICO),
5760
"js" | "mjs" | "jsonp" => Some(JAVASCRIPT),
5861
"json" => Some(JSON),
59-
"css" => Some(CSS),
62+
"otf" => Some(OTF),
6063
"svg" => Some(SVG),
64+
"ttf" => Some(TTF),
65+
"txt" => Some(PLAIN),
66+
"webp" => Some(WEBP),
67+
"woff" => Some(WOFF),
68+
"woff2" => Some(WOFF2),
6169
"xml" => Some(XML),
6270
_ => None,
6371
}

0 commit comments

Comments
 (0)