pub fn from_path(path: &str) -> &'static str {
let ext = path
.rsplit('/')
.next()
.and_then(|name| name.rsplit_once('.'))
.map(|(_, ext)| ext)
.unwrap_or("");
let ext = ext.to_ascii_lowercase();
match ext.as_str() {
"html" | "htm" => "text/html; charset=utf-8",
"css" => "text/css; charset=utf-8",
"js" | "mjs" => "text/javascript; charset=utf-8",
"json" => "application/json",
"xml" => "application/xml",
"txt" | "text" | "md" => "text/plain; charset=utf-8",
"csv" => "text/csv; charset=utf-8",
"svg" => "image/svg+xml",
"png" => "image/png",
"jpg" | "jpeg" => "image/jpeg",
"gif" => "image/gif",
"webp" => "image/webp",
"avif" => "image/avif",
"ico" => "image/x-icon",
"bmp" => "image/bmp",
"woff" => "font/woff",
"woff2" => "font/woff2",
"ttf" => "font/ttf",
"otf" => "font/otf",
"pdf" => "application/pdf",
"wasm" => "application/wasm",
"zip" => "application/zip",
"gz" => "application/gzip",
"tar" => "application/x-tar",
"mp4" => "video/mp4",
"webm" => "video/webm",
"mp3" => "audio/mpeg",
"ogg" => "audio/ogg",
"wav" => "audio/wav",
_ => "application/octet-stream",
}
}
pub fn is_precompressed(content_type: &str) -> bool {
let ct = content_type
.split(';')
.next()
.unwrap_or(content_type)
.trim();
matches!(
ct,
"image/png"
| "image/jpeg"
| "image/gif"
| "image/webp"
| "image/avif"
| "video/mp4"
| "video/webm"
| "audio/mpeg"
| "audio/ogg"
| "application/gzip"
| "application/zip"
| "application/wasm"
| "font/woff"
| "font/woff2"
)
}