From 4d9e6afa116a56b433326f23a83673bd569e6d52 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Thu, 21 Sep 2017 18:36:11 -0700 Subject: [PATCH] Document case-insensitivity of 'from_ext'. --- lib/src/http/content_type.rs | 7 +++++-- lib/src/http/media_type.rs | 7 +++++-- lib/src/response/named_file.rs | 6 ++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/src/http/content_type.rs b/lib/src/http/content_type.rs index 835fdb58..646ed0fe 100644 --- a/lib/src/http/content_type.rs +++ b/lib/src/http/content_type.rs @@ -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: diff --git a/lib/src/http/media_type.rs b/lib/src/http/media_type.rs index eb9d047c..8d19e0de 100644 --- a/lib/src/http/media_type.rs +++ b/lib/src/http/media_type.rs @@ -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: diff --git a/lib/src/response/named_file.rs b/lib/src/response/named_file.rs index f41391e8..c2de0e37 100644 --- a/lib/src/response/named_file.rs +++ b/lib/src/response/named_file.rs @@ -83,10 +83,8 @@ impl Responder<'static> for NamedFile { fn respond_to(self, _: &Request) -> Result, 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); } }