Net.HTTP.MediaType

lib/Net/HTTP/MediaType.gob

A media type (RFC 9110 §8.3.1): text/html; charset=utf-8, what a Content-Type says a body is, and what an Accept asks for.

The type, the subtype and parameter names are case-insensitive, and are stored lowercase. Parameter values keep their case, since some are case-sensitive, and are held unquoted: parameter(m, "charset") of text/plain; charset="utf-8" is utf-8. toString quotes a value only where a token cannot spell it.

Media ranges, as Accept writes them, are media types too: * is a token, so */* and text/* parse, and q is a parameter like any other.

type MediaType
let json : MediaType
let eventStream : MediaType
let plainText : MediaType
let html : MediaType
let formURLEncoded : MediaType
let octetStream : MediaType
let any : MediaType

*/*, the range that matches every media type.

fun parse : fun(String) -> Option MediaType

media-type = type "/" subtype parameters

fun literal : fun(String) -> MediaType

Returns the media type text writes, and panics if it writes none.

fun read : fun(Cursor) -> Option MediaType

Reads a media type at the cursor, and leaves the cursor after it. This is for the fields that hold a media type among other things; parse reads one that is all of its text.

parameters = *( OWS ";" OWS [ parameter ] ) parameter = name "=" ( token / quoted-string )

A parameter named twice is refused: which one counts is not defined, and two readers that choose differently disagree about the body.

fun toString : fun(MediaType) -> String
fun mainType : fun(MediaType) -> String
fun subtype : fun(MediaType) -> String
fun essence : fun(MediaType) -> String

Returns the type and subtype without parameters: text/html.

fun parameter : fun(MediaType, String) -> Option String

Returns the value of the parameter name, which is case-insensitive.

fun parameters : fun(MediaType) -> Array (String, String)
fun withParameter : fun(MediaType, String, String) -> Option MediaType

Returns m with the parameter name set to value, replacing one of that name. Returns None if name is not a token, or value holds a byte a quoted string cannot carry.

fun matches : fun(MediaType, MediaType) -> Bool

Whether the media range range matches m (RFC 9110 §12.5.1): */* matches everything, text/* every text type, and otherwise the essences must be equal. Each of the range's parameters other than q must be one m has.

instance Eq MediaType

Two media types are equal when their types, subtypes and parameters are, the parameters in order.

instance Show MediaType