Document case-insensitivity of 'from_ext'.

This commit is contained in:
Sergio Benitez 2017-09-21 18:36:11 -07:00
parent c36701671b
commit 4d9e6afa11
3 changed files with 12 additions and 8 deletions

View File

@ -84,17 +84,20 @@ impl ContentType {
/// extensions is not recognized, then this method returns `None`. The
/// currently recognized extensions are txt, html, htm, xml, csv, js, css,
/// json, png, gif, bmp, jpeg, jpg, webp, svg, pdf, ttf, otf, woff, and
/// woff2.
/// woff2. Extensions are matched case-insensitively.
///
/// # Example
///
/// A recognized content type:
/// Recognized content types:
///
/// ```rust
/// use rocket::http::ContentType;
///
/// let xml = ContentType::from_extension("xml");
/// assert_eq!(xml, Some(ContentType::XML));
///
/// let xml = ContentType::from_extension("XML");
/// assert_eq!(xml, Some(ContentType::XML));
/// ```
///
/// An unrecognized content type:

View File

@ -144,17 +144,20 @@ macro_rules! from_extension {
/// extensions are recognized. If an extensions is not recognized,
/// `None` is returned. The currently recognized extensions are
$(#[doc=$ext]#[doc=","])*
/// and is likely to grow.
/// and is likely to grow. Extensions are matched case-insensitively.
///
/// # Example
///
/// A recognized media type:
/// Recognized media types:
///
/// ```rust
/// use rocket::http::MediaType;
///
/// let xml = MediaType::from_extension("xml");
/// assert_eq!(xml, Some(MediaType::XML));
///
/// let xml = MediaType::from_extension("XML");
/// assert_eq!(xml, Some(MediaType::XML));
/// ```
///
/// An unrecognized media type:

View File

@ -83,10 +83,8 @@ impl Responder<'static> for NamedFile {
fn respond_to(self, _: &Request) -> Result<Response<'static>, Status> {
let mut response = Response::new();
if let Some(ext) = self.path().extension() {
// TODO: Use Cow for lowercase.
let ext_string = ext.to_string_lossy().to_lowercase();
if let Some(content_type) = ContentType::from_extension(&ext_string) {
response.set_header(content_type);
if let Some(ct) = ContentType::from_extension(&ext.to_string_lossy()) {
response.set_header(ct);
}
}