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