Add webp, ttf, otf, woff, and woff2 as known Content-Types.

This commit is contained in:
Michael Aaron Murphy 2017-02-16 18:31:20 -05:00 committed by Sergio Benitez
parent 46403b8d0a
commit 4161949a1c
1 changed files with 15 additions and 5 deletions

View File

@ -10,7 +10,7 @@ use http::ascii::{uncased_eq, UncasedAscii};
/// ///
/// # Usage /// # Usage
/// ///
/// ContentTypes should rarely be created directly. Instead, an associated /// `ContentTypes` should rarely be created directly. Instead, an associated
/// constant should be used; one is declared for most commonly used content /// constant should be used; one is declared for most commonly used content
/// types. /// types.
/// ///
@ -114,8 +114,13 @@ impl ContentType {
"GIF", GIF, is_gif => "image", "gif", "GIF", GIF, is_gif => "image", "gif",
"BMP", BMP, is_bmp => "image", "bmp", "BMP", BMP, is_bmp => "image", "bmp",
"JPEG", JPEG, is_jpeg => "image", "jpeg", "JPEG", JPEG, is_jpeg => "image", "jpeg",
"WEBP", WEBP, is_webp => "image", "webp",
"SVG", SVG, is_svg => "image", "svg+xml", "SVG", SVG, is_svg => "image", "svg+xml",
"PDF", PDF, is_pdf => "application", "pdf" "PDF", PDF, is_pdf => "application", "pdf",
"TTF", TTF, is_ttf => "application", "font-sfnt",
"OTF", OTF, is_otf => "application", "font-sfnt",
"WOFF", WOFF, is_woff => "application", "font-woff",
"WOFF2", WOFF2, is_woff2 => "font", "woff2"
} }
/// Returns the Content-Type associated with the extension `ext`. Not all /// Returns the Content-Type associated with the extension `ext`. Not all
@ -158,8 +163,13 @@ impl ContentType {
x if uncased_eq(x, "bmp") => ContentType::BMP, x if uncased_eq(x, "bmp") => ContentType::BMP,
x if uncased_eq(x, "jpeg") => ContentType::JPEG, x if uncased_eq(x, "jpeg") => ContentType::JPEG,
x if uncased_eq(x, "jpg") => ContentType::JPEG, x if uncased_eq(x, "jpg") => ContentType::JPEG,
x if uncased_eq(x, "webp") => ContentType::WEBP,
x if uncased_eq(x, "svg") => ContentType::SVG, x if uncased_eq(x, "svg") => ContentType::SVG,
x if uncased_eq(x, "pdf") => ContentType::PDF, x if uncased_eq(x, "pdf") => ContentType::PDF,
x if uncased_eq(x, "ttf") => ContentType::TTF,
x if uncased_eq(x, "otf") => ContentType::OTF,
x if uncased_eq(x, "woff") => ContentType::WOFF,
x if uncased_eq(x, "woff2") => ContentType::WOFF2,
_ => ContentType::Any _ => ContentType::Any
} }
} }
@ -210,7 +220,7 @@ impl ContentType {
ContentType { ContentType {
ttype: UncasedAscii::from(ttype), ttype: UncasedAscii::from(ttype),
subtype: UncasedAscii::from(subtype), subtype: UncasedAscii::from(subtype),
params: params.map(|p| UncasedAscii::from(p)) params: params.map(UncasedAscii::from)
} }
} }
@ -245,9 +255,9 @@ impl ContentType {
None => "" None => ""
}; };
params.split(";") params.split(';')
.filter_map(|param| { .filter_map(|param| {
let mut kv = param.split("="); let mut kv = param.split('=');
match (kv.next(), kv.next()) { match (kv.next(), kv.next()) {
(Some(key), Some(val)) => Some((key.trim(), val.trim())), (Some(key), Some(val)) => Some((key.trim(), val.trim())),
_ => None _ => None