1 {-# LANGUAGE OverloadedStrings #-}
2 module Symantic.HTTP.Mime.Type where
4 import Data.Function (($))
5 import Data.Proxy (Proxy(..))
6 import qualified Network.HTTP.Media as Media
8 -- * Class 'MediaTypeable'
9 class MediaTypeable mt where
10 mimeType :: Proxy mt -> MediaType
11 mimeTypes :: Proxy mt -> [MediaType]
12 mimeTypes mt = [mimeType mt]
13 type MediaType = Media.MediaType
14 instance MediaTypeable () where
15 mimeType _mt = mimeAny
17 charsetUTF8 :: MediaType -> MediaType
18 charsetUTF8 = (Media./: ("charset", "utf-8"))
25 mimeJSON :: Proxy JSON
27 instance MediaTypeable JSON where
28 mimeType _mt = charsetUTF8 $ "application"Media.//"json"
29 mimeTypes mt = [mimeType mt, "application"Media.//"json"]
33 mimeHTML :: Proxy HTML
35 instance MediaTypeable HTML where
36 mimeType _mt = charsetUTF8 $ "text"Media.//"html"
37 mimeTypes mt = [mimeType mt, "text"Media.//"html"]
39 -- ** Type 'FormUrlEncoded'
41 mimeFormUrlEncoded :: Proxy FormUrlEncoded
42 mimeFormUrlEncoded = Proxy
43 instance MediaTypeable FormUrlEncoded where
44 mimeType _mt = "application"Media.//"x-www-form-urlencoded"
46 -- ** Type 'OctetStream'
48 mimeOctetStream :: Proxy OctetStream
49 mimeOctetStream = Proxy
50 instance MediaTypeable OctetStream where
51 mimeType _mt = "application"Media.//"octet-stream"
53 -- ** Type 'PlainText'
55 mimePlainText :: Proxy PlainText
57 instance MediaTypeable PlainText where
58 mimeType _mt = charsetUTF8 $ "text"Media.//"plain"