http-media: Processing HTTP Content-Type and Accept headers
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.
Modules
[Index] [Quick Jump]
Downloads
- http-media-0.8.1.1.tar.gz [browse] (Cabal source package)
- Package description (revised from the package)
Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.
Maintainer's Corner
For package maintainers and hackage trustees
Candidates
- No Candidates
Versions [RSS] | 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, 0.7.1.1, 0.7.1.2, 0.7.1.3, 0.8.0.0, 0.8.1.0, 0.8.1.1 |
---|---|
Change log | CHANGES.md |
Dependencies | base (>=4.8 && <5), bytestring (>=0.10 && <0.13), case-insensitive (>=1.0 && <1.3), containers (>=0.5 && <0.8), utf8-string (>=0.3 && <1.1) [details] |
Tested with | ghc ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.8 || ==9.4.8 || ==9.6.5 || ==9.8.2 |
License | MIT |
Copyright | (c) 2012-2024 Timothy Jones |
Author | Timothy Jones |
Maintainer | Timothy Jones <tim@zmthy.net> |
Revised | Revision 2 made by TimothyJones at 2024-05-17T05:19:14Z |
Category | Web |
Home page | https://github.com/zmthy/http-media |
Bug tracker | https://github.com/zmthy/http-media/issues |
Source repo | head: git clone https://github.com/zmthy/http-media |
Uploaded | by TimothyJones at 2023-09-10T07:00:50Z |
Distributions | Arch:0.8.1.1, Debian:0.8.0.0, Fedora:0.8.0.0, LTSHaskell:0.8.1.1, NixOS:0.8.1.1, Stackage:0.8.1.1, openSUSE:0.8.1.1 |
Reverse Dependencies | 159 direct, 682 indirect [details] |
Downloads | 51243 total (263 in the last 30 days) |
Rating | (no votes yet) [estimated by Bayesian average] |
Your Rating | |
Status | Docs available [build log] Last success reported on 2023-09-10 [all 1 reports] |