Package0.8.1.1Web
http-media
Processing HTTP Content-Type and Accept headers
- Version0.8.1.1
- CategoryWeb
- LicenceMIT
- AuthorTimothy Jones
- MaintainerTimothy Jones <tim@zmthy.net>
- Homepagegithub.com/zmthy/http-media
- Pinned byhackage http-media 0.8.1.1
- Sourcehackage.haskell.org/package/http-media-0.8.1.1
Modules
7 modules- Network.HTTP.Media38A framework for parsing HTTP media type headers.
- Network.HTTP.Media.Accept1Defines the Accept type class, designed to unify types on the matching
- Network.HTTP.Media.Charset1Defines the Charset accept header with an Accept instance for use in
- Network.HTTP.Media.Encoding1Defines the Encoding accept header with an Accept instance for use in
- Network.HTTP.Media.Language2Defines the Language accept header with an Accept instance for use in
- Network.HTTP.Media.MediaType9Defines the MediaType accept header with an Accept instance for use
- Network.HTTP.Media.RenderHeader1Defines the RenderHeader type class, with the renderHeader method.
Description
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.
Depends on
5 packages- base-4.20.2.0with GHC
- bytestring-0.12.2.0with GHC
- case-insensitive-1.2.1.0in this set
- containers-0.7with GHC
- utf8-string-1.0.2in this set