Giter VIP home page Giter VIP logo

typebeat's Introduction

TypeBeat - Agnostic parser of the Content-Type in OCaml

Build Status

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.

Instalation

TypeBeat can be installed with opam:

opam install type-beat

Explanation

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 does that mean? The parser expects an End of input or any character other 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
 charset="utf-8"

And it is still valid (see RFC822)!

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

Build Requirements

  • OCaml >= 4.01.0
  • Angstrom
  • topkg, ocamlfind and ocamlbuild to build the project

Improvement

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

typebeat's People

Contributors

avsm avatar craigfe avatar dinosaure avatar hannesm avatar olleolleolle avatar seliopou avatar vbmithr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

typebeat's Issues

Introduce a mime type

Often, only the mime type is used. Would it be possible to define a mime type, and include a value of this type in the contenttype ? This would allow to manipule mime types more easily.

Something like

type mime = (ty, subty)
type content = { mime: mime ; ...}

or if you want to keep a record type:

type mime = { ty : ty ; subty: subty }
type content = { mime: mime ; ...}

Of course it would be great to have mime_of_string, string_of_mime functions, too.

TypeBeat.to_string

Hi,

When sending HTTP requests, it is usual to indicate the accepted type of document, for example using the Accept: text/turtle, */* header. So it may be useful to print values of type content, not just parse. Do you plan to add a TypeBeat.to_string function ?

Next release.

According to #22, we should prepare a release. I will waiting @vbmithr for some incomes and try to re-integrate my improvements from mrmime into this package.

Archive type beat

This project is not used by anybody and I don't have time to improve/release it. We should archive this repository, I will keep this issue open one week if someone really use it and I will archive it then.

Subtypes starting with 'x' should be accepted

application/xhtml+xml is not accepted, because subtype starts with x, but it is a valid subtype. application/html+xml is accepted:

# TypeBeat.of_string "application/xhtml+xml";;
- : (TypeBeat.content, TypeBeat.error) result =
Error (`Invalid ("char '-'", []))
# TypeBeat.of_string "application/html+xml";;
- : (TypeBeat.content, TypeBeat.error) result =
Ok {TypeBeat.ty = `Application; subty = `X_token "html+xml"; parameters = []}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.