mirror of https://github.com/rwf2/Rocket.git
Document case-insensitivity of 'from_ext'.
This commit is contained in:
parent
c36701671b
commit
4d9e6afa11
|
@ -84,17 +84,20 @@ impl ContentType {
|
||||||
/// extensions is not recognized, then this method returns `None`. The
|
/// extensions is not recognized, then this method returns `None`. The
|
||||||
/// currently recognized extensions are txt, html, htm, xml, csv, js, css,
|
/// currently recognized extensions are txt, html, htm, xml, csv, js, css,
|
||||||
/// json, png, gif, bmp, jpeg, jpg, webp, svg, pdf, ttf, otf, woff, and
|
/// json, png, gif, bmp, jpeg, jpg, webp, svg, pdf, ttf, otf, woff, and
|
||||||
/// woff2.
|
/// woff2. Extensions are matched case-insensitively.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// A recognized content type:
|
/// Recognized content types:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use rocket::http::ContentType;
|
/// use rocket::http::ContentType;
|
||||||
///
|
///
|
||||||
/// let xml = ContentType::from_extension("xml");
|
/// let xml = ContentType::from_extension("xml");
|
||||||
/// assert_eq!(xml, Some(ContentType::XML));
|
/// assert_eq!(xml, Some(ContentType::XML));
|
||||||
|
///
|
||||||
|
/// let xml = ContentType::from_extension("XML");
|
||||||
|
/// assert_eq!(xml, Some(ContentType::XML));
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// An unrecognized content type:
|
/// An unrecognized content type:
|
||||||
|
|
|
@ -144,17 +144,20 @@ macro_rules! from_extension {
|
||||||
/// extensions are recognized. If an extensions is not recognized,
|
/// extensions are recognized. If an extensions is not recognized,
|
||||||
/// `None` is returned. The currently recognized extensions are
|
/// `None` is returned. The currently recognized extensions are
|
||||||
$(#[doc=$ext]#[doc=","])*
|
$(#[doc=$ext]#[doc=","])*
|
||||||
/// and is likely to grow.
|
/// and is likely to grow. Extensions are matched case-insensitively.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// A recognized media type:
|
/// Recognized media types:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use rocket::http::MediaType;
|
/// use rocket::http::MediaType;
|
||||||
///
|
///
|
||||||
/// let xml = MediaType::from_extension("xml");
|
/// let xml = MediaType::from_extension("xml");
|
||||||
/// assert_eq!(xml, Some(MediaType::XML));
|
/// assert_eq!(xml, Some(MediaType::XML));
|
||||||
|
///
|
||||||
|
/// let xml = MediaType::from_extension("XML");
|
||||||
|
/// assert_eq!(xml, Some(MediaType::XML));
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// An unrecognized media type:
|
/// An unrecognized media type:
|
||||||
|
|
|
@ -83,10 +83,8 @@ impl Responder<'static> for NamedFile {
|
||||||
fn respond_to(self, _: &Request) -> Result<Response<'static>, Status> {
|
fn respond_to(self, _: &Request) -> Result<Response<'static>, Status> {
|
||||||
let mut response = Response::new();
|
let mut response = Response::new();
|
||||||
if let Some(ext) = self.path().extension() {
|
if let Some(ext) = self.path().extension() {
|
||||||
// TODO: Use Cow for lowercase.
|
if let Some(ct) = ContentType::from_extension(&ext.to_string_lossy()) {
|
||||||
let ext_string = ext.to_string_lossy().to_lowercase();
|
response.set_header(ct);
|
||||||
if let Some(content_type) = ContentType::from_extension(&ext_string) {
|
|
||||||
response.set_header(content_type);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue