Skip to content

ContentTypes

[Source]

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.

class val ContentTypes

Constructors

create

[Source]

Create a ContentTypes with the 17 standard defaults.

new val create()
: ContentTypes val^

Returns


Public Functions

add

[Source]

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.

fun val add(
  ext: String val,
  mime: String val)
: ContentTypes val

Parameters

Returns


apply

[Source]

Look up the MIME type for ext. Returns application/octet-stream when the extension is not in the map.

fun box apply(
  ext: String val)
: String val

Parameters

Returns