1 {-# LANGUAGE OverloadedStrings #-}
3 module Symantic.HTTP.Mime.Type where
5 import Data.Typeable (Typeable(..))
6 import Data.Function (($))
7 import Data.Proxy (Proxy(..))
8 import qualified Network.HTTP.Media as Media
10 -- * Class 'MediaTypeable'
11 class MediaTypeable mt where
12 mimeType :: Proxy mt -> MediaType
13 mimeTypes :: Proxy mt -> [MediaType]
14 mimeTypes mt = [mimeType mt]
15 type MediaType = Media.MediaType
16 instance MediaTypeable () where
17 mimeType _mt = mimeAny
19 charsetUTF8 :: MediaType -> MediaType
20 charsetUTF8 = (Media./: ("charset", "utf-8"))
27 mimeJSON :: Proxy JSON
29 instance MediaTypeable JSON where
30 mimeType _mt = charsetUTF8 $ "application"Media.//"json"
31 mimeTypes mt = [mimeType mt, "application"Media.//"json"]
35 mimeHTML :: Proxy HTML
37 instance MediaTypeable HTML where
38 mimeType _mt = charsetUTF8 $ "text"Media.//"html"
39 mimeTypes mt = [mimeType mt, "text"Media.//"html"]
41 -- ** Type 'FormUrlEncoded'
43 mimeFormUrlEncoded :: Proxy FormUrlEncoded
44 mimeFormUrlEncoded = Proxy
45 instance MediaTypeable FormUrlEncoded where
46 mimeType _mt = "application"Media.//"x-www-form-urlencoded"
48 -- ** Type 'OctetStream'
50 mimeOctetStream :: Proxy OctetStream
51 mimeOctetStream = Proxy
52 instance MediaTypeable OctetStream where
53 mimeType _mt = "application"Media.//"octet-stream"
55 -- ** Type 'PlainText'
57 mimePlainText :: Proxy PlainText
59 instance MediaTypeable PlainText where
60 mimeType _mt = charsetUTF8 $ "text"Media.//"plain"