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
|
||||
/// 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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue