http-media: Processing HTTP Content-Type and Accept headers

[ library, mit, web ] [ Propose Tags ]

This library is intended to be a comprehensive solution to parsing media types, including quality parameters, in HTTP headers. It addresses parsing of the Content-Type and Accept headers, and includes general data types for matching against the other accept headers as well. It encodes MIME parameters into a MediaType data, and allows the matching of the final value by comparing quality values from the client.

In the following example, the Accept header is parsed, and then matched against a list of server options to serve the appropriate media:

getHeader >>= maybe send406Error sendResourceWith . mapAcceptMedia
    [ ("text/html",        asHtml)
    , ("application/json", asJson)

Similarly, the Content-Type header can be used to produce a parser for request bodies based on the given content type:

getContentType >>= maybe send415Error readRequestBodyWith . mapContentMedia
    [ ("application/json", parseJson)
    , ("text/plain",       parseText)

The API is agnostic to your choice of server.

Versions [faq] 0.1.0, 0.1.1, 0.2.0, 0.3.0, 0.4.0, 0.5.0, 0.5.1, 0.6.0, 0.6.1, 0.6.2, 0.6.3, 0.6.4, 0.7.0, 0.7.1,,,,
Dependencies base (>=4.6.0 && <5.0), bytestring (>=0.10.0 && <0.11), containers (>=0.5.0 && <0.6), utf8-string (>=0.3.7 && <0.4) [details]
License MIT
Copyright (c) 2012-2014 Timothy Jones
Author Timothy Jones
Maintainer Timothy Jones <>
Category Web
Home page
Bug tracker
Source repo head: git clone git://
Uploaded by TimothyJones at Thu Jul 31 14:23:16 UTC 2014
Distributions Arch:, Debian:, Fedora:, LTSHaskell:, NixOS:, Stackage:
Downloads 21675 total (558 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Successful builds reported [all 1 reports]




Maintainer's Corner

For package maintainers and hackage trustees