@@ -1,4 +1,5 @@
1{-# LANGUAGE DataKinds #-}
1{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE ConstraintKinds #-}
2{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE MultiParamTypeClasses #-}
4{-# LANGUAGE MultiParamTypeClasses #-}
4{-# LANGUAGE OverloadedStrings #-}
5{-# LANGUAGE OverloadedStrings #-}
@@ -17,6 +18,7 @@ import Data.Proxy (Proxy(..))
17import Data.String.Conversions (cs)
18import Data.String.Conversions (cs)
18import qualified Data.Text.Lazy.Encoding as Text
19import qualified Data.Text.Lazy.Encoding as Text
19import qualified Data.Text.Lazy as Text
20import qualified Data.Text.Lazy as Text
21+import GHC.Exts (Constraint)
20import qualified Network.HTTP.Media as M
22import qualified Network.HTTP.Media as M
@@ -39,7 +41,7 @@ class Accept ctype where
40-- | @text/html;charset=utf-8@
42-- | @text/html;charset=utf-8@
41instance Accept HTML where
43instance Accept HTML where
42− contentType _ = "text" M.// "html"
44+ contentType _ = "text" M.// "html" M./: ("charset", "utf-8")
44-- | @application/json;charset=utf-8@
46-- | @application/json;charset=utf-8@
45instance Accept JSON where
47instance Accept JSON where
@@ -47,19 +49,19 @@ instance Accept JSON where
48-- | @application/xml;charset=utf-8@
50-- | @application/xml;charset=utf-8@
49instance Accept XML where
51instance Accept XML where
50− contentType _ = "application" M.// "xml"
52+ contentType _ = "application" M.// "xml" M./: ("charset", "utf-8")
52-- | @application/javascript;charset=utf-8@
54-- | @application/javascript;charset=utf-8@
53instance Accept JavaScript where
55instance Accept JavaScript where
54− contentType _ = "application" M.// "javascript"
56+ contentType _ = "application" M.// "javascript" M./: ("charset", "utf-8")
56-- | @text/css;charset=utf-8@
58-- | @text/css;charset=utf-8@
57instance Accept CSS where
59instance Accept CSS where
58− contentType _ = "text" M.// "css"
60+ contentType _ = "text" M.// "css" M./: ("charset", "utf-8")
60-- | @text/plain;charset=utf-8@
62-- | @text/plain;charset=utf-8@
61instance Accept PlainText where
63instance Accept PlainText where
62− contentType _ = "text" M.// "plain"
64+ contentType _ = "text" M.// "plain" M./: ("charset", "utf-8")
64-- | @application/octet-stream@
66-- | @application/octet-stream@
65instance Accept OctetStream where
67instance Accept OctetStream where
@@ -93,7 +95,7 @@ class AllCTRender list a where
93 -- mimetype).
95 -- mimetype).
94 handleAcceptH :: Proxy list -> AcceptHeader -> a -> Maybe (ByteString, ByteString)
96 handleAcceptH :: Proxy list -> AcceptHeader -> a -> Maybe (ByteString, ByteString)
96−instance ( AllMimeRender ctyps a, IsEmpty ctyps ~ 'False
98+instance ( AllMimeRender ctyps a, IsNonEmpty ctyps
97 ) => AllCTRender ctyps a where
99 ) => AllCTRender ctyps a where
98 handleAcceptH _ (AcceptHeader accept) val = M.mapAcceptMedia lkup accept
100 handleAcceptH _ (AcceptHeader accept) val = M.mapAcceptMedia lkup accept
99 where pctyps = Proxy :: Proxy ctyps
101 where pctyps = Proxy :: Proxy ctyps
@@ -125,7 +127,7 @@ class AllCTUnrender list a where
125 -> ByteString -- Request body
127 -> ByteString -- Request body
126 -> Maybe a
128 -> Maybe a
128−instance ( AllMimeUnrender ctyps a, IsEmpty ctyps ~ 'False
130+instance ( AllMimeUnrender ctyps a, IsNonEmpty ctyps
129 ) => AllCTUnrender ctyps a where
131 ) => AllCTUnrender ctyps a where
130 handleCTypeH _ ctypeH body = join $ M.mapContentMedia lkup (cs ctypeH)
132 handleCTypeH _ ctypeH body = join $ M.mapContentMedia lkup (cs ctypeH)
131 where lkup = amu (Proxy :: Proxy ctyps) body
133 where lkup = amu (Proxy :: Proxy ctyps) body
@@ -182,9 +184,9 @@ instance ( MimeUnrender ctyp a
182 pctyps = Proxy :: Proxy ctyps
184 pctyps = Proxy :: Proxy ctyps
183 pctyp' = Proxy :: Proxy ctyp'
185 pctyp' = Proxy :: Proxy ctyp'
185−type family IsEmpty (ls::[*]) where
187+type family IsNonEmpty (ls::[*]) :: Constraint where
186− IsEmpty '[] = 'True
188+ IsNonEmpty '[] = 'False ~ 'True
187− IsEmpty x = 'False
189+ IsNonEmpty x = ()
189--------------------------------------------------------------------------
191--------------------------------------------------------------------------
190-- * MimeUnrender Instances
192-- * MimeUnrender Instances