@@ -15,6 +15,8 @@ module Servant.Client.Core.Internal.Request where
1515import Prelude ()
1616import Prelude.Compat
1717
18+import Control.DeepSeq
19+ (NFData (..))
1820import Control.Monad.Catch
1921 (Exception)
2022import qualified Data.ByteString as BS
@@ -34,10 +36,10 @@ import Data.Typeable
3436import GHC.Generics
3537 (Generic)
3638import Network.HTTP.Media
37− (MediaType)
39+ (MediaType, mainType, parameters, subType)
3840import Network.HTTP.Types
39− (Header, HeaderName, HttpVersion, Method, QueryItem, Status,
40− http11, methodGet)
41+ (Header, HeaderName, HttpVersion (..), Method, QueryItem,
42+ Status (..), http11, methodGet)
4143import Web.HttpApiData
4244 (ToHttpApiData, toEncodedUrlPiece, toHeader)
4345
@@ -59,6 +61,20 @@ data ServantError =
5961
6062instance Exception ServantError
6163
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`
69+ rnf res
70+ where
71+ mediaTypeRnf mt =
72+ rnf (mainType mt) `seq`
73+ rnf (subType mt) `seq`
74+ rnf (parameters mt)
75+ rnf (InvalidContentTypeHeader res) = rnf res
76+ rnf (ConnectionError err) = rnf err
77+
6278data RequestF a = Request
6379 { requestPath :: a
6480 , requestQueryString :: Seq.Seq QueryItem
@@ -88,6 +104,16 @@ data GenResponse a = Response
88104 , responseBody :: a
89105 } deriving (Eq, Show, Generic, Typeable, Functor, Foldable, Traversable)
90106
107+instance NFData a => NFData (GenResponse a) where
108+ rnf (Response sc hs hv body) =
109+ rnfStatus sc `seq`
110+ rnf hs `seq`
111+ rnfHttpVersion hv `seq`
112+ rnf body
113+ where
114+ rnfStatus (Status code msg) = rnf code `seq` rnf msg
115+ rnfHttpVersion (HttpVersion _ _) = () -- HttpVersion fields are strict
116+
91117type Response = GenResponse LBS.ByteString
92118type StreamingResponse = GenResponse (IO BS.ByteString)
93119