Package Info

ghc-http-media


Processing HTTP Content-Type and Accept headers


Unspecified

This library is intended to be a comprehensive solution to parsing and selecting quality-indexed values in HTTP headers. It is capable of parsing both media types and language parameters from the Accept and Content header families, and can be extended to match against other accept headers as well. Selecting the appropriate header value is achieved by comparing a list of server options against the quality-indexed values supplied by 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 using 'mapAcceptMedia':

> 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 with 'mapContentMedia':

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

The API is agnostic to your choice of server.


License: MIT
URL: https://hackage.haskell.org/package/http-media

Categories

Releases

Package Version Update ID Released Package Hub Version Platforms Subpackages
0.8.0.0-bp155.3.16 info GA Release 2023-05-22 15 SP5
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • ghc-http-media
  • ghc-http-media-devel
0.8.0.0-bp154.2.12 info GA Release 2022-05-09 15 SP4
  • AArch64
  • ppc64le
  • x86-64
  • ghc-http-media
  • ghc-http-media-devel
0.6.4-bp150.2.3 info GA Release 2018-08-01 15
  • AArch64
  • ghc-http-media
  • ghc-http-media-devel
0.6.4-bp150.2.7 info GA Release 2018-07-31 15
  • ppc64le
  • ghc-http-media
  • ghc-http-media-devel
0.6.4-bp150.2.8 info GA Release 2018-07-30 15
  • x86-64
  • ghc-http-media
  • ghc-http-media-devel