std::net::mimeMIME type detection.
Determine the MIME content type of a file by its path or extension.
Useful for HTTP servers that need to set Content-Type headers.
import std.net.mime;
fn main() {
let ct = mime.from_path("index.html");
println(ct); // "text/html"
if mime.is_text(ct) {
println("text file");
}
}
from_pathDetect the MIME type from a file path.
Uses the file extension to determine the type. Returns
"application/octet-stream" for unknown extensions.
import std.net.mime;
fn main() {
println(mime.from_path("photo.jpg")); // "image/jpeg"
println(mime.from_path("style.css")); // "text/css"
println(mime.from_path("data.json")); // "application/json"
}
from_extDetect the MIME type from a file extension (without the dot).
import std.net.mime;
fn main() {
println(mime.from_ext("html")); // "text/html"
println(mime.from_ext("png")); // "image/png"
}
is_textTest whether a MIME type is a text type (e.g. text/*).
is_imageTest whether a MIME type is an image type (e.g. image/*).
is_audioTest whether a MIME type is an audio type (e.g. audio/*).
is_videoTest whether a MIME type is a video type (e.g. video/*).