@@ -15,6 +15,8 @@ module Servant.Client.Core.Internal.Request where
15import Prelude ()
15import Prelude ()
16import Prelude.Compat
16import Prelude.Compat
18+import Control.DeepSeq
18import Control.Monad.Catch
20import Control.Monad.Catch
19 (Exception)
21 (Exception)
20import qualified Data.ByteString as BS
22import qualified Data.ByteString as BS
@@ -34,10 +36,10 @@ import Data.Typeable
34import GHC.Generics
36import GHC.Generics
36import Network.HTTP.Media
38import Network.HTTP.Media
37− (MediaType)
39+ (MediaType, mainType, parameters, subType)
38import Network.HTTP.Types
40import Network.HTTP.Types
39− (Header, HeaderName, HttpVersion, Method, QueryItem, Status,
41+ (Header, HeaderName, HttpVersion (..), Method, QueryItem,
40− http11, methodGet)
42+ Status (..), http11, methodGet)
41import Web.HttpApiData
43import Web.HttpApiData
42 (ToHttpApiData, toEncodedUrlPiece, toHeader)
44 (ToHttpApiData, toEncodedUrlPiece, toHeader)
@@ -59,6 +61,20 @@ data ServantError =
60instance Exception ServantError
62instance Exception ServantError
64+instance NFData ServantError where
65+ rnf (FailureResponse res) = rnf res
66+ rnf (DecodeFailure err res) = rnf err `seq` rnf res
67+ rnf (UnsupportedContentType mt' res) =
68+ mediaTypeRnf mt' `seq`
72+ rnf (mainType mt) `seq`
73+ rnf (subType mt) `seq`
75+ rnf (InvalidContentTypeHeader res) = rnf res
76+ rnf (ConnectionError err) = rnf err
62data RequestF a = Request
78data RequestF a = Request
63 { requestPath :: a
79 { requestPath :: a
64 , requestQueryString :: Seq.Seq QueryItem
80 , requestQueryString :: Seq.Seq QueryItem
@@ -88,6 +104,16 @@ data GenResponse a = Response
88 , responseBody :: a
104 , responseBody :: a
89 } deriving (Eq, Show, Generic, Typeable, Functor, Foldable, Traversable)
105 } deriving (Eq, Show, Generic, Typeable, Functor, Foldable, Traversable)
107+instance NFData a => NFData (GenResponse a) where
108+ rnf (Response sc hs hv body) =
111+ rnfHttpVersion hv `seq`
114+ rnfStatus (Status code msg) = rnf code `seq` rnf msg
115+ rnfHttpVersion (HttpVersion _ _) = () -- HttpVersion fields are strict
91type Response = GenResponse LBS.ByteString
117type Response = GenResponse LBS.ByteString
92type StreamingResponse = GenResponse (IO BS.ByteString)
118type StreamingResponse = GenResponse (IO BS.ByteString)