ContentTypes¶
Map file extensions to MIME content types.
Ships with 17 common defaults (html, css, js, json, xml, txt, png, jpg,
jpeg, gif, svg, ico, woff, woff2, pdf, wasm, htm). Chain add calls to
add custom mappings or override defaults — each call returns a new
ContentTypes with the entry added:
let types = hobby.ContentTypes
.add("webp", "image/webp")
.add("avif", "image/avif")
hobby.ServeFiles(root where content_types = types)
Lookups are case-insensitive — both the default keys and user-provided keys
are lowercased. Unknown extensions return application/octet-stream.
Constructors¶
create¶
Create a ContentTypes with the 17 standard defaults.
Returns¶
- ContentTypes val^
Public Functions¶
add¶
Return a new ContentTypes with the given mapping added. If ext
already exists, the new MIME type replaces the previous one. The
extension is lowercased before insertion so lookups are always
case-insensitive.
Parameters¶
Returns¶
- ContentTypes val
apply¶
Look up the MIME type for ext. Returns application/octet-stream when
the extension is not in the map.
Parameters¶
- ext: String val
Returns¶
- String val