mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 16:02:59 +01:00
expose fs::file_extension_to_mime() function
This commit is contained in:
parent
9151d61eda
commit
3751656722
20
src/fs.rs
20
src/fs.rs
@ -29,6 +29,14 @@ use param::FromParam;
|
|||||||
/// Env variable for default cpu pool size for `StaticFiles`
|
/// Env variable for default cpu pool size for `StaticFiles`
|
||||||
const ENV_CPU_POOL_VAR: &str = "ACTIX_FS_POOL";
|
const ENV_CPU_POOL_VAR: &str = "ACTIX_FS_POOL";
|
||||||
|
|
||||||
|
/// Return the MIME type associated with a filename extension (case-insensitive).
|
||||||
|
/// If `ext` is empty or no associated type for the extension was found, returns
|
||||||
|
/// the type `application/octet-stream`.
|
||||||
|
#[inline]
|
||||||
|
pub fn file_extension_to_mime(ext: &str) -> mime::Mime {
|
||||||
|
get_mime_type(ext)
|
||||||
|
}
|
||||||
|
|
||||||
/// A file with an associated name; responds with the Content-Type based on the
|
/// A file with an associated name; responds with the Content-Type based on the
|
||||||
/// file extension.
|
/// file extension.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -692,6 +700,18 @@ mod tests {
|
|||||||
use http::{header, Method, StatusCode};
|
use http::{header, Method, StatusCode};
|
||||||
use test::{self, TestRequest};
|
use test::{self, TestRequest};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_file_extension_to_mime() {
|
||||||
|
let m = file_extension_to_mime("jpg");
|
||||||
|
assert_eq!(m, mime::IMAGE_JPEG);
|
||||||
|
|
||||||
|
let m = file_extension_to_mime("invalid extension!!");
|
||||||
|
assert_eq!(m, mime::APPLICATION_OCTET_STREAM);
|
||||||
|
|
||||||
|
let m = file_extension_to_mime("");
|
||||||
|
assert_eq!(m, mime::APPLICATION_OCTET_STREAM);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_named_file_text() {
|
fn test_named_file_text() {
|
||||||
assert!(NamedFile::open("test--").is_err());
|
assert!(NamedFile::open("test--").is_err());
|
||||||
|
Loading…
Reference in New Issue
Block a user