Parse a media type.

Description

Parsed according to RFC 2616, as at http://pretty-rfc.herokuapp.com/RFC2616#media.types.

Usage

1

Details

A simplified minimal EBNF is:

  • media-type = type "/" subtype *( ";" parameter )

  • type = token

  • subtype = token

  • parameter = attribute "=" value

  • attribute = token

  • value = token | quoted-string

  • token = 1*<any CHAR except CTLs or ()<>@,;:\"/[]?=

  • quoted-string = " *(any text except ", unless escaped with \) "

Examples

1
2
3
4
parse_media("text/plain")
parse_media("text/plain; charset=utf-8")
parse_media("text/plain; charset=\"utf-8\"")
parse_media("text/plain; randomparam=\";=;=\"")

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.