A parser for the Content-Type value

TypeBeat is a pure implementation of the parsing of the Content-Type's value
(see RFC822 and
RFC2045). The reason of this light
library is to compute a complex rule. Indeed, it's hard to parse the value
of the Content-Type, believe me.

So it's a common library if you want to know the value of the Content-Type and
don't worry, we respect the standard. We saved
the IANA
database too.


TypeBeat can be installed with opam:

opam install type-beat


TypeBeat uses the cool and funny Angstrom library to parse the value of the
Content-Type. If you want to implement an email parser (like
MrMime) or an HTTP server
(CoHTTP), firstly, these already
exist, too bad.

This parser handles complex rules like the CFWS token and other weird rules
from old and stupid RFCs. The point is to centralize all these parsers in one
library (because you can find the Content-Type crazy rule in some different
protocols) .

Then, the API was designed to be easy to use:

val of_string : string -> (content, error) result
val of_string_raw : string -> int -> int -> (content * int, error) result

The first transforms its string argument into a Content-Type value. The
second is generally used by another parser (like an HTTP protocol parser) to
parse a part of the string and return how many bytes the parser consumed.

If you are a warrior of the Angstrom library, you can use the parser:

val parser : content Angstrom.t

But the parser does not terminate because we have the CFWS token at the end.
What that means? The parser expect an End of input or any character different
than wsp (and you can produce that by Angstrom.Unbuffered.Complete) to
check that the hypothetical next line is a new field. Because, as you know, we
can write something like:

Content-Type: text/html;^CRLF

And it still valid (see RFC822)!

Another point is that this library has all
of IANA media
type database (dated from 2016-06-01), so we recognize the IANA media types

Build Requirements

  • OCaml >= 4.01.0

  • Angstrom

  • topkg, ocamlfind and ocamlbuild to build the project


If you want something from the RFC822, I can provide that in this library.

31 Mar 2017
= "0.5.0"
>= "4.03.0"
Reverse Dependencies