@@ -11,11 +11,10 @@
11{-# LANGUAGE TypeFamilies #-}
11{-# LANGUAGE TypeFamilies #-}
12{-# LANGUAGE TypeOperators #-}
12{-# LANGUAGE TypeOperators #-}
13{-# LANGUAGE UndecidableInstances #-}
13{-# LANGUAGE UndecidableInstances #-}
14−#if !MIN_VERSION_base(4,8,0)
15−{-# LANGUAGE OverlappingInstances #-}
17{-# OPTIONS_HADDOCK not-home #-}
14{-# OPTIONS_HADDOCK not-home #-}
16+#include "overlapping-compat.h"
19-- | A collection of basic Content-Types (also known as Internet Media
18-- | A collection of basic Content-Types (also known as Internet Media
20-- Types, or MIME types). Additionally, this module provides classes that
19-- Types, or MIME types). Additionally, this module provides classes that
21-- encapsulate how to serialize or deserialize values to or from
20-- encapsulate how to serialize or deserialize values to or from
@@ -57,6 +56,9 @@ module Servant.API.ContentTypes
57 , MimeRender(..)
56 , MimeRender(..)
58 , MimeUnrender(..)
57 , MimeUnrender(..)
60 -- * Internal
62 -- * Internal
61 , AcceptHeader(..)
63 , AcceptHeader(..)
62 , AllCTRender(..)
64 , AllCTRender(..)
@@ -75,8 +77,7 @@ import Control.Applicative ((*>), (<*))
76import Control.Arrow (left)
78import Control.Arrow (left)
77import Control.Monad
79import Control.Monad
78−import Data.Aeson (FromJSON, ToJSON, encode,
80+import Data.Aeson (FromJSON(..), ToJSON(..), encode)
80import Data.Aeson.Parser (value)
81import Data.Aeson.Parser (value)
81import Data.Aeson.Types (parseEither)
82import Data.Aeson.Types (parseEither)
82import Data.Attoparsec.ByteString.Char8 (endOfInput, parseOnly,
83import Data.Attoparsec.ByteString.Char8 (endOfInput, parseOnly,
@@ -168,10 +169,7 @@ class (AllMime list) => AllCTRender (list :: [*]) a where
168 -- mimetype).
169 -- mimetype).
169 handleAcceptH :: Proxy list -> AcceptHeader -> a -> Maybe (ByteString, ByteString)
170 handleAcceptH :: Proxy list -> AcceptHeader -> a -> Maybe (ByteString, ByteString)
171−instance
172+instance OVERLAPPABLE_
172−#if MIN_VERSION_base(4,8,0)
173− {-# OVERLAPPABLE #-}
175 (AllMimeRender (ct ': cts) a) => AllCTRender (ct ': cts) a where
173 (AllMimeRender (ct ': cts) a) => AllCTRender (ct ': cts) a where
176 handleAcceptH _ (AcceptHeader accept) val = M.mapAcceptMedia lkup accept
174 handleAcceptH _ (AcceptHeader accept) val = M.mapAcceptMedia lkup accept
177 where pctyps = Proxy :: Proxy (ct ': cts)
175 where pctyps = Proxy :: Proxy (ct ': cts)
@@ -275,20 +273,14 @@ instance ( MimeUnrender ctyp a
275-- * MimeRender Instances
273-- * MimeRender Instances
277-- | `encode`
275-- | `encode`
278−instance
276+instance OVERLAPPABLE_
279−#if MIN_VERSION_base(4,8,0)
280− {-# OVERLAPPABLE #-}
282 ToJSON a => MimeRender JSON a where
277 ToJSON a => MimeRender JSON a where
283 mimeRender _ = encode
278 mimeRender _ = encode
285-- | @encodeFormUrlEncoded . toFormUrlEncoded@
280-- | @encodeFormUrlEncoded . toFormUrlEncoded@
286-- Note that the @mimeUnrender p (mimeRender p x) == Right x@ law only
281-- Note that the @mimeUnrender p (mimeRender p x) == Right x@ law only
287-- holds if every element of x is non-null (i.e., not @("", "")@)
282-- holds if every element of x is non-null (i.e., not @("", "")@)
288−instance
283+instance OVERLAPPABLE_
289−#if MIN_VERSION_base(4,8,0)
290− {-# OVERLAPPABLE #-}
292 ToFormUrlEncoded a => MimeRender FormUrlEncoded a where
284 ToFormUrlEncoded a => MimeRender FormUrlEncoded a where
293 mimeRender _ = encodeFormUrlEncoded . toFormUrlEncoded
285 mimeRender _ = encodeFormUrlEncoded . toFormUrlEncoded
@@ -312,25 +304,27 @@ instance MimeRender OctetStream ByteString where
312instance MimeRender OctetStream BS.ByteString where
304instance MimeRender OctetStream BS.ByteString where
313 mimeRender _ = fromStrict
305 mimeRender _ = fromStrict
315−instance
307+-- | A type for responses with content-body.
316−#if MIN_VERSION_base(4,8,0)
308+data NoContent = NoContent
317− {-# OVERLAPPING #-}
309+ deriving (Show, Eq, Read)
311+instance FromJSON NoContent where
312+ parseJSON _ = return NoContent
314+instance ToJSON NoContent where
318+instance OVERLAPPING_
319− MimeRender JSON () where
319+ MimeRender JSON NoContent where
320 mimeRender _ _ = ""
320 mimeRender _ _ = ""
322−instance
322+instance OVERLAPPING_
323−#if MIN_VERSION_base(4,8,0)
326− MimeRender PlainText () where
323+ MimeRender PlainText NoContent where
327 mimeRender _ _ = ""
324 mimeRender _ _ = ""
329−instance
326+instance OVERLAPPING_
330−#if MIN_VERSION_base(4,8,0)
333− MimeRender OctetStream () where
327+ MimeRender OctetStream NoContent where
334 mimeRender _ _ = ""
328 mimeRender _ _ = ""
336--------------------------------------------------------------------------
330--------------------------------------------------------------------------