ic-asset-router 0.1.1

File-based HTTP routing with IC response certification for Internet Computer canisters
Documentation
/// Determine the MIME type for a file path based on its extension.
///
/// Covers common web asset types (HTML, CSS, JS, images, fonts, media,
/// archives). Returns `"application/octet-stream"` for unrecognized
/// extensions.
pub fn get_mime_type(path: &str) -> &'static str {
    let extension = path.rsplit('.').next().unwrap_or("");

    match extension.to_lowercase().as_str() {
        // Text / markup
        "html" | "htm" => "text/html",
        "css" => "text/css",
        "txt" => "text/plain",

        // Data / APIs
        "json" => "application/json",
        "xml" => "application/xml",
        "csv" => "text/csv",
        "yaml" | "yml" => "application/yaml",
        "map" => "application/json",

        // JavaScript / WASM
        "js" => "application/javascript",
        "wasm" => "application/wasm",

        // Images
        "png" => "image/png",
        "jpg" | "jpeg" => "image/jpeg",
        "gif" => "image/gif",
        "svg" => "image/svg+xml",
        "webp" => "image/webp",
        "avif" => "image/avif",
        "heic" => "image/heic",
        "ico" => "image/x-icon",

        // Fonts
        "woff2" => "font/woff2",
        "woff" => "font/woff",
        "eot" => "application/vnd.ms-fontobject",
        "ttf" => "font/ttf",
        "otf" => "font/otf",

        // Media
        "mp3" => "audio/mpeg",
        "ogg" => "audio/ogg",
        "mp4" => "video/mp4",
        "webm" => "video/webm",

        // Web app manifests
        "webmanifest" => "application/manifest+json",

        // Archives / binaries
        "pdf" => "application/pdf",
        "zip" => "application/zip",

        // Fallback
        _ => "application/octet-stream",
    }
}