]> Git — Sourcephile - haskell/symantic-http.git/blob - Symantic/HTTP/Mime/Type.hs
Rename stuffs and init client testing
[haskell/symantic-http.git] / Symantic / HTTP / Mime / Type.hs
1 {-# LANGUAGE OverloadedStrings #-}
2 {-# LANGUAGE GADTs #-}
3 module Symantic.HTTP.Mime.Type where
4
5 import Data.Typeable (Typeable(..))
6 import Data.Function (($))
7 import Data.Proxy (Proxy(..))
8 import qualified Network.HTTP.Media as Media
9
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
18
19 charsetUTF8 :: MediaType -> MediaType
20 charsetUTF8 = (Media./: ("charset", "utf-8"))
21
22 mimeAny :: MediaType
23 mimeAny = "*/*"
24
25 -- ** Type 'JSON'
26 data JSON
27 mimeJSON :: Proxy JSON
28 mimeJSON = Proxy
29 instance MediaTypeable JSON where
30 mimeType _mt = charsetUTF8 $ "application"Media.//"json"
31 mimeTypes mt = [mimeType mt, "application"Media.//"json"]
32
33 -- ** Type 'HTML'
34 data HTML
35 mimeHTML :: Proxy HTML
36 mimeHTML = Proxy
37 instance MediaTypeable HTML where
38 mimeType _mt = charsetUTF8 $ "text"Media.//"html"
39 mimeTypes mt = [mimeType mt, "text"Media.//"html"]
40
41 -- ** Type 'FormUrlEncoded'
42 data FormUrlEncoded
43 mimeFormUrlEncoded :: Proxy FormUrlEncoded
44 mimeFormUrlEncoded = Proxy
45 instance MediaTypeable FormUrlEncoded where
46 mimeType _mt = "application"Media.//"x-www-form-urlencoded"
47
48 -- ** Type 'OctetStream'
49 data OctetStream
50 mimeOctetStream :: Proxy OctetStream
51 mimeOctetStream = Proxy
52 instance MediaTypeable OctetStream where
53 mimeType _mt = "application"Media.//"octet-stream"
54
55 -- ** Type 'PlainText'
56 data PlainText
57 mimePlainText :: Proxy PlainText
58 mimePlainText = Proxy
59 instance MediaTypeable PlainText where
60 mimeType _mt = charsetUTF8 $ "text"Media.//"plain"