Skip to main content

media_type

Function media_type 

Source
pub fn media_type(file: &Path) -> Option<&'static str>
Expand description

The media type of a file, or None when the set does not hold it.

use majordomus_cli::web::serve::media_type;
use std::path::Path;
assert_eq!(media_type(Path::new("a/index.html")), Some("text/html; charset=utf-8"));
assert_eq!(media_type(Path::new("a/results.json")), Some("application/json"));
assert_eq!(media_type(Path::new("a/binary.wasm")), None);
assert_eq!(media_type(Path::new("noextension")), None);