Standard library · The web
web/mime
Imported as import "web/mime" as mime, its names are then mime.…. Every signature below is the one the checker infers.
The media type a file is served as, from its name: mime.of_path("a/b.png") is image/png. The table is the hundred-odd types a web server meets; anything else is application/octet-stream, which is what a browser treats as "download it".
mime.of_path("site/index.html") # => text/html mime.of_ext("json") # => application/json mime.is_text("application/json") # => true mime.ext_of("image/jpeg") # => Some(jpg)
Functions
fn of_path(path: Str) -> Str
mime.of_path("a/b.png") # => image/png mime.of_path("README") # => application/octet-stream
fn fallback() -> Str
mime.fallback() # => application/octet-stream
fn of_ext(ext: Str) -> Str
The type for an extension, without its dot, in any case.
mime.of_ext("JPG") # => image/jpeg mime.of_ext("wasm") # => application/wasm
fn ext_of(kind: Str) -> Option(Str)
An extension for a type — the usual one where several exist.
mime.ext_of("text/html") # => Some(html) mime.ext_of("x-made-up/thing") # => None
fn is_text(kind: Str) -> Bool
Whether the type is text, and is served with a charset: the text/ types, and the structured ones that are text too.
mime.is_text("text/css") # => true mime.is_text("image/png") # => false mime.is_text("image/svg+xml") # => true
Tests
test_by_path_and_extensiontest_text_or_nottest_the_table_is_well_formed