@@ -1,69 +1,30 @@
11module Servant.QuickCheck.Internal.Predicates where
22
3−import Control.Exception (catch, throw)
4−import Control.Monad (liftM2, unless, when)
5−import Data.Aeson (Object, decode)
6−import Data.Bifunctor (first)
7−import qualified Data.ByteString as SBS
3+import Control.Monad
4+import Data.Aeson (Object, decode)
5+import Data.Bifunctor (Bifunctor (..))
6+import qualified Data.ByteString.Lazy as LBS
7+import qualified Data.ByteString as SBS
88import qualified Data.ByteString.Char8 as SBSC
9−import qualified Data.ByteString.Lazy as LBS
10−import Data.CaseInsensitive (foldCase, foldedCase, mk)
11−import Data.Either (isRight)
12−import Data.List.Split (wordsBy)
13−import Data.Maybe (fromMaybe, isJust)
14−import Data.Semigroup (Semigroup (..))
15−import qualified Data.Text as T
16−import Data.Time (UTCTime, defaultTimeLocale, parseTimeM,
17− rfc822DateFormat)
18−import GHC.Generics (Generic)
19−import Network.HTTP.Client (Manager, Request, Response, httpLbs,
20− method, parseRequest, requestHeaders,
21− responseBody, responseHeaders,
22− responseStatus)
23−import Network.HTTP.Media (matchAccept)
24−import Network.HTTP.Types (methodGet, methodHead, parseMethod,
25− renderStdMethod, status100, status200,
26− status201, status300, status401,
27− status405, status500)
28−import Prelude.Compat
29−import System.Clock (Clock (Monotonic), diffTimeSpec,
30− getTime, toNanoSecs)
31−
32−import Servant.QuickCheck.Internal.ErrorTypes
33−
34−
35−-- | [__Best Practice__]
36−--
37−-- @500 Internal Server Error@ should be avoided - it may represent some
9+import Data.CaseInsensitive (mk)
10+import Data.Either (isRight)
11+import Data.List.Split (wordsBy)
12+import Data.Monoid ((<>))
13+import Data.Text (Text)
14+import GHC.Generics (Generic)
15+import Network.HTTP.Client (Manager, Request, Response, httpLbs,
16+ responseBody, responseStatus, responseHeaders)
17+import Network.HTTP.Types (status500, status405, parseMethod)
18+
19+-- | @500 Internal Server Error@ should be avoided - it may represent some
3820-- issue with the application code, and it moreover gives the client little
3921-- indication of how to proceed or what went wrong.
4022--
4123-- This function checks that the response code is not 500.
42−--
43−-- /Since 0.0.0.0/
44−not500 :: ResponsePredicate
45−not500 = ResponsePredicate $ \resp ->
46− when (responseStatus resp == status500) $ throw $ PredicateFailure "not500" Nothing resp
24+not500 :: ResponsePredicate Text Bool
25+not500 = ResponsePredicate "not500" (\resp -> not $ responseStatus resp == status500)
4726
48−-- | [__Optional__]
49−--
50−-- This function checks that the response from the server does not take longer
51−-- than the specified number of nanoseconds.
52−--
53−-- /Since 0.0.2.1/
54−notLongerThan :: Integer -> RequestPredicate
55−notLongerThan maxAllowed
56− = RequestPredicate $ \req mgr -> do
57− start <- getTime Monotonic
58− resp <- httpLbs req mgr
59− end <- getTime Monotonic
60− when (toNanoSecs (end `diffTimeSpec` start) > maxAllowed) $
61− throw $ PredicateFailure "notLongerThan" (Just req) resp
62− return []
63−
64−-- | [__Best Practice__]
65−--
66−-- Returning anything other than an object when returning JSON is considered
27+-- | Returning anything other than an object when returning JSON is considered
6728-- bad practice, as:
6829--
6930-- (1) it is hard to modify the returned value while maintaining backwards
@@ -80,197 +41,79 @@ notLongerThan maxAllowed
8041--
8142-- * JSON Grammar: <https://tools.ietf.org/html/rfc7159#section-2 RFC 7159 Section 2>
8243-- * JSON Grammar: <https://tools.ietf.org/html/rfc4627#section-2 RFC 4627 Section 2>
83−--
84−-- /Since 0.0.0.0/
85−onlyJsonObjects :: ResponsePredicate
44+onlyJsonObjects :: ResponsePredicate Text Bool
8645onlyJsonObjects
87− = ResponsePredicate (\resp -> do
88− case lookup "content-type" (first foldedCase <$> responseHeaders resp) of
89− Nothing -> return ()
90− Just ctype -> when ("application/json" `SBS.isPrefixOf` ctype) $ do
91− case (decode (responseBody resp) :: Maybe Object) of
92− Nothing -> throw $ PredicateFailure "onlyJsonObjects" Nothing resp
93− Just _ -> return ())
94−
95−-- | __Optional__
96−--
97−-- When creating a new resource, it is good practice to provide a @Location@
46+ = ResponsePredicate "onlyJsonObjects" (\resp -> case decode (responseBody resp) of
47+ Nothing -> False
48+ Just (_ :: Object) -> True)
49+
50+{-
51+-- | When creating a new resource, it is good practice to provide a @Location@
9852-- header with a link to the created resource.
9953--
10054-- This function checks that every @201 Created@ response contains a @Location@
10155-- header, and that the link in it responds with a 2XX response code to @GET@
10256-- requests.
10357--
104−-- This is considered optional because other means of linking to the resource
105−-- (e.g. via the response body) are also acceptable; linking to the resource in
106−-- some way is considered best practice.
107−--
108−-- __References__:
109−--
110−-- * 201 Created: <https://tools.ietf.org/html/rfc7231#section-6.3.2 RFC 7231 Section 6.3.2>
111−-- * Location header: <https://tools.ietf.org/html/rfc7231#section-7.1.2 RFC 7231 Section 7.1.2>
112−--
113−-- /Since 0.0.0.0/
114−createContainsValidLocation :: RequestPredicate
58+-- References: <RFC 7231, Section 6.3.2 https://tools.ietf.org/html/rfc7231#section-6.3.2>
59+createContainsValidLocation :: ResponsePredicate Text Bool
11560createContainsValidLocation
116− = RequestPredicate $ \req mgr -> do
117− let n = "createContainsValidLocation"
118− resp <- httpLbs req mgr
119− if responseStatus resp == status201
120− then case lookup "Location" $ responseHeaders resp of
121− Nothing -> throw $ PredicateFailure n (Just req) resp
122− Just l -> case parseRequest $ SBSC.unpack l of
123− Nothing -> throw $ PredicateFailure n (Just req) resp
124− Just x -> do
125− resp2 <- httpLbs x mgr
126− status2XX (Just req) resp2 n
127− return [resp, resp2]
128− else return [resp]
129−
130−-- | [__Optional__]
131−--
132−-- The @Last-Modified@ header represents the time a resource was last
133−-- modified. It is used to drive caching and conditional requests.
134−--
135−-- When using this mechanism, the server adds the @Last-Modified@ header to
136−-- responses. Clients may then make requests with the @If-Modified-Since@
137−-- header to conditionally request resources. If the resource has not
138−-- changed since that date, the server responds with a status code of 304
139−-- (@Not Modified@) without a response body.
140−--
141−-- The @Last-Modified@ header can also be used in conjunction with the
142−-- @If-Unmodified-Since@ header to drive optimistic concurrency.
143−--
144−-- The @Last-Modified@ date must be in RFC 822 format.
145−--
146−-- __References__:
147−--
148−-- * 304 Not Modified: <https://tools.ietf.org/html/rfc7232#section-4.1 RFC 7232 Section 4.1>
149−-- * Last-Modified header: <https://tools.ietf.org/html/rfc7232#section-2.2 RFC 7232 Section 2.2>
150−-- * If-Modified-Since header: <https://tools.ietf.org/html/rfc7232#section-3.3 RFC 7232 Section 3.3>
151−-- * If-Unmodified-Since header: <https://tools.ietf.org/html/rfc7232#section-3.4 RFC 7232 Section 3.4>
152−-- * Date format: <https://tools.ietf.org/html/rfc2616#section-3.3 RFC 2616 Section 3.3>
153−--
154−-- /Since 0.0.2.1/
155−getsHaveLastModifiedHeader :: RequestPredicate
156−getsHaveLastModifiedHeader
157− = RequestPredicate $ \req mgr ->
158− if (method req == methodGet)
159− then do
160− resp <- httpLbs req mgr
161− unless (hasValidHeader "Last-Modified" isRFC822Date resp) $ do
162− throw $ PredicateFailure "getsHaveLastModifiedHeader" (Just req) resp
163− return [resp]
164− else return []
165−
61+ = ResponsePredicate "createContainsValidLocation" (\resp ->
16662
63+getsHaveLastModifiedHeader :: ResponsePredicate Text Bool
64+getsHaveLastModifiedHeader
65+ = ResponsePredicate "getsHaveLastModifiedHeader" (\resp ->
16766
168−-- | [__RFC Compliance__]
169−--
170−-- When an HTTP request has a method that is not allowed,
171−-- a 405 response should be returned. Additionally, it is good practice to
172−-- return an @Allow@
67+-}
68+-- | When an HTTP request has a method that is not allowed, a 405 response
69+-- should be returned. Additionally, it is good practice to return an @Allow@
17370-- header with the list of allowed methods.
17471--
17572-- This function checks that every @405 Method Not Allowed@ response contains
17673-- an @Allow@ header with a list of standard HTTP methods.
17774--
178−-- Note that 'servant' itself does not currently set the @Allow@ headers.
179−--
18075-- __References__:
18176--
18277-- * @Allow@ header: <https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html RFC 2616 Section 14.7>
183−-- * Status 405: <https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html RFC 2616 Section 10.4.6>
184−-- * Servant Allow header issue: <https://github.com/haskell-servant/servant/issues/489 Issue #489>
185−--
186−-- /Since 0.0.0.0/
187−notAllowedContainsAllowHeader :: RequestPredicate
78+notAllowedContainsAllowHeader :: ResponsePredicate Text Bool
18879notAllowedContainsAllowHeader
189− = RequestPredicate $ \req mgr -> do
190− let reqs = [ req { method = renderStdMethod m } | m <- [minBound .. maxBound]
191− , renderStdMethod m /= method req ]
192− resp <- mapM (flip httpLbs mgr) reqs
193−
194− case filter pred' (zip reqs resp) of
195− (x:_) -> throw $ PredicateFailure "notAllowedContainsAllowHeader" (Just $ fst x) (snd x)
196− [] -> return resp
197− where
198− pred' (_, resp) = responseStatus resp == status405 && not (hasValidHeader "Allow" go resp)
199− where
200− go x = all (\y -> isRight $ parseMethod $ SBSC.pack y)
201− $ wordsBy (`elem` (", " :: [Char])) (SBSC.unpack x)
202−
203−
204−-- | [__RFC Compliance__]
205−--
206−-- When a request contains an @Accept@ header, the server must either return
80+ = ResponsePredicate "notAllowedContainsAllowHeader" (\resp ->
81+ if responseStatus resp == status405
82+ then hasValidHeader "Allow" go resp
83+ else True)
84+ where
85+ go x = all (\y -> isRight $ parseMethod $ SBSC.pack y)
86+ $ wordsBy (`elem` (", " :: [Char])) (SBSC.unpack x)
87+
88+ {-
89+-- | When a request contains an @Accept@ header, the server must either return
20790-- content in one of the requested representations, or respond with @406 Not
20891-- Acceptable@.
20992--
21093-- This function checks that every *successful* response has a @Content-Type@
211−-- header that matches the @Accept@ header. It does *not* check that the server
212−-- matches the quality descriptions of the @Accept@ header correctly.
213−--
214−-- __References__:
215−--
216−-- * @Accept@ header: <https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html RFC 2616 Section 14.1>
217−--
218−-- /Since 0.0.0.0/
219−honoursAcceptHeader :: RequestPredicate
94+-- header that matches the @Accept@ header.
95+honoursAcceptHeader :: Predicate b Bool
22096honoursAcceptHeader
221− = RequestPredicate $ \req mgr -> do
222− resp <- httpLbs req mgr
223− let scode = responseStatus resp
224− sctype = lookup "Content-Type" $ responseHeaders resp
225− sacc = fromMaybe "*/*" $ lookup "Accept" (requestHeaders req)
226− if status100 < scode && scode < status300
227− then if isJust $ sctype >>= \x -> matchAccept [x] sacc
228− then throw $ PredicateFailure "honoursAcceptHeader" (Just req) resp
229− else return [resp]
230− else return [resp]
231−
232−
233−-- | [__Best Practice__]
234−--
235−-- Whether or not a representation should be cached, it is good practice to
97+ = RequestPredicate "honoursAcceptHeader" _
98+
99+-- | Whether or not a representation should be cached, it is good practice to
236100-- have a @Cache-Control@ header for @GET@ requests. If the representation
237101-- should not be cached, used @Cache-Control: no-cache@.
238102--
239−-- This function checks that @GET@ responses have @Cache-Control@ header.
240−-- It does NOT currently check that the header is valid.
241−--
242−-- __References__:
103+-- This function checks that @GET@ responses have a valid @Cache-Control@
104+-- header.
243105--
244−-- * @Cache-Control@ header: <https://tools.ietf.org/html/rfc7234#section-5.2 RFC 7234 Section 5.2>
245−--
246−-- /Since 0.0.0.0/
247−getsHaveCacheControlHeader :: RequestPredicate
106+-- References: RFC 7234 Section 5.2
107+-- https://tools.ietf.org/html/rfc7234#section-5.2
108+getsHaveCacheControlHeader :: Predicate b Bool
248109getsHaveCacheControlHeader
249− = RequestPredicate $ \req mgr ->
250− if (method req == methodGet)
251− then do
252− resp <- httpLbs req mgr
253− unless (hasValidHeader "Cache-Control" (const True) resp) $ do
254− throw $ PredicateFailure "getsHaveCacheControlHeader" (Just req) resp
255− return [resp]
256− else return []
257−
258−-- | [__Best Practice__]
259−--
260−-- Like 'getsHaveCacheControlHeader', but for @HEAD@ requests.
261−--
262−-- /Since 0.0.0.0/
263−headsHaveCacheControlHeader :: RequestPredicate
110+ = ResponsePredicate "getsHaveCacheControlHeader" _
111+
112+-- | Like 'getsHaveCacheControlHeader', but for @HEAD@ requests.
113+headsHaveCacheControlHeader :: Predicate b Bool
264114headsHaveCacheControlHeader
265− = RequestPredicate $ \req mgr ->
266− if (method req == methodHead)
267− then do
268− resp <- httpLbs req mgr
269− unless (hasValidHeader "Cache-Control" (const True) resp) $
270− throw $ PredicateFailure "headsHaveCacheControlHeader" (Just req) resp
271− return [resp]
272− else return []
273−{-
115+ = ResponsePredicate "headsHaveCacheControlHeader" _
116+
274117-- |
275118--
276119-- If the original request modifies the resource, this function makes two
@@ -311,56 +154,23 @@ optionsContainsValidAllow
311154-- This function checks that any @Link@ headers have values in the correct
312155-- format.
313156--
314−-- __References__:
315−--
316−-- * <https://tools.ietf.org/html/rfc5988 RFC 5988 Section 5>
157+-- References: RFC 5988 Section 5
158+-- https://tools.ietf.org/html/rfc5988
317159linkHeadersAreValid :: Predicate b Bool
318160linkHeadersAreValid
319161 = ResponsePredicate "linkHeadersAreValid" _
320162
321−-}
322−-- | [__RFC Compliance__]
323−--
324−-- Any @401 Unauthorized@ response must include a @WWW-Authenticate@ header.
163+-- | Any @401 Unauthorized@ response must include a @WWW-Authenticate@ header.
325164--
326165-- This function checks that, if a response has status code 401, it contains a
327166-- @WWW-Authenticate@ header.
328167--
329−-- __References__:
330−--
331−-- * @WWW-Authenticate@ header: <https://tools.ietf.org/html/rfc7235#section-4.1 RFC 7235 Section 4.1>
332−--
333−-- /Since 0.0.0.0/
334−unauthorizedContainsWWWAuthenticate :: ResponsePredicate
168+-- References: RFC 7235 Section 4.1
169+-- https://tools.ietf.org/html/rfc7235#section-4.1
170+unauthorizedContainsWWWAuthenticate :: Predicate b Bool
335171unauthorizedContainsWWWAuthenticate
336− = ResponsePredicate $ \resp ->
337− if responseStatus resp == status401
338− then unless (hasValidHeader "WWW-Authenticate" (const True) resp) $
339− throw $ PredicateFailure "unauthorizedContainsWWWAuthenticate" Nothing resp
340− else return ()
341−
342−
343−-- | [__RFC Compliance__]
344−--
345−-- [An HTML] document will start with exactly this string: <!DOCTYPE html>
346−--
347−-- This function checks that HTML documents (those with `Content-Type: text/html...`)
348−-- include a DOCTYPE declaration at the top. We do not enforce capital case for the string `DOCTYPE`.
349−--
350−-- __References__:
351−--
352−-- * HTML5 Doctype: <https://tools.ietf.org/html/rfc7992#section-6.1 RFC 7992 Section 6.1>
353−-- /Since 0.3.0.0/
354−htmlIncludesDoctype :: ResponsePredicate
355−htmlIncludesDoctype
356− = ResponsePredicate $ \resp ->
357− if hasValidHeader "Content-Type" (SBS.isPrefixOf . foldCase $ "text/html") resp
358− then do
359− let htmlContent = foldCase . LBS.take 20 $ responseBody resp
360− unless (LBS.isPrefixOf (foldCase "<!doctype html>") htmlContent) $
361− throw $ PredicateFailure "htmlIncludesDoctype" Nothing resp
362− else return ()
363−
172+ = ResponsePredicate "unauthorizedContainsWWWAuthenticate" _
173+-}
364174-- * Predicate logic
365175
366176-- The idea with all this footwork is to not waste any requests. Rather than
@@ -369,77 +179,79 @@ htmlIncludesDoctype
369179--
370180-- Still, this is all kind of ugly.
371181
372−-- | A predicate that depends only on the response.
373−--
374−-- /Since 0.0.0.0/
375−newtype ResponsePredicate = ResponsePredicate
376− { getResponsePredicate :: Response LBS.ByteString -> IO ()
377− } deriving (Generic)
182+data ResponsePredicate n r = ResponsePredicate
183+ { respPredName :: n
184+ , respPred :: Response LBS.ByteString -> r
185+ } deriving (Functor, Generic)
378186
379−instance Semigroup ResponsePredicate where
380− ResponsePredicate a <> ResponsePredicate b = ResponsePredicate $ \x -> a x >> b x
187+instance Bifunctor ResponsePredicate where
188+ first f (ResponsePredicate a b) = ResponsePredicate (f a) b
189+ second = fmap
381190
382−instance Monoid ResponsePredicate where
383− mempty = ResponsePredicate $ const $ return ()
384− mappend = (<>)
191+instance (Monoid n, Monoid r) => Monoid (ResponsePredicate n r) where
192+ mempty = ResponsePredicate mempty mempty
193+ a `mappend` b = ResponsePredicate
194+ { respPredName = respPredName a <> respPredName b
195+ , respPred = respPred a <> respPred b
196+ }
385197
386−-- | A predicate that depends on both the request and the response.
387−--
388−-- /Since 0.0.0.0/
389−newtype RequestPredicate = RequestPredicate
390− { getRequestPredicate :: Request -> Manager -> IO [Response LBS.ByteString]
391− } deriving (Generic)
198+data RequestPredicate n r = RequestPredicate
199+ { reqPredName :: n
200+ , reqResps :: Request -> Manager -> IO [Response LBS.ByteString]
201+ , reqPred :: ResponsePredicate n r
202+ } deriving (Generic, Functor)
392203
393−-- TODO: This isn't actually a monoid
394−instance Monoid RequestPredicate where
395− mempty = RequestPredicate (\r m -> httpLbs r m >>= \x -> return ([x]))
396− mappend = (<>)
204+instance Bifunctor RequestPredicate where
205+ first f (RequestPredicate a b c) = RequestPredicate (f a) b (first f c)
206+ second = fmap
397207
398208-- TODO: This isn't actually a monoid
399−instance Semigroup RequestPredicate where
400− RequestPredicate a <> RequestPredicate b = RequestPredicate $ \r mgr ->
401− liftM2 (<>) (a r mgr) (b r mgr)
402−
403−-- | A set of predicates. Construct one with 'mempty' and '<%>'.
404−data Predicates = Predicates
405− { requestPredicates :: RequestPredicate
406− , responsePredicates :: ResponsePredicate
407− } deriving (Generic)
209+instance (Monoid n, Monoid r) => Monoid (RequestPredicate n r) where
210+ mempty = RequestPredicate mempty (\r m -> return <$> httpLbs r m) mempty
211+ a `mappend` b = RequestPredicate
212+ { reqPredName = reqPredName a <> reqPredName b
213+ , reqResps = \x m -> liftM2 (<>) (reqResps a x m) (reqResps b x m)
214+ , reqPred = reqPred a <> reqPred b
215+ }
216+
217+data Predicates n r = Predicates
218+ { reqPreds :: RequestPredicate n r
219+ , respPreds :: ResponsePredicate n r
220+ } deriving (Generic, Functor)
221+
222+instance (Monoid n, Monoid r) => Monoid (Predicates n r) where
223+ mempty = Predicates mempty mempty
224+ a `mappend` b = Predicates (reqPreds a <> reqPreds b) (respPreds a <> respPreds b)
408225
409−instance Semigroup Predicates where
410− a <> b = Predicates (requestPredicates a <> requestPredicates b)
411− (responsePredicates a <> responsePredicates b)
412226
413−instance Monoid Predicates where
414− mempty = Predicates mempty mempty
415− mappend = (<>)
416227
417228class JoinPreds a where
418− joinPreds :: a -> Predicates -> Predicates
229+ joinPreds :: a -> Predicates [Text] [Text] -> Predicates [Text] [Text]
230+
231+instance JoinPreds (RequestPredicate Text Bool) where
232+ joinPreds p (Predicates x y) = Predicates (go <> x) y
233+ where go = let p' = first return p
234+ in fmap (\z -> if z then [] else reqPredName p') p'
419235
420−instance JoinPreds (RequestPredicate ) where
421− joinPreds p (Predicates x y) = Predicates (p <> x) y
236+instance JoinPreds (ResponsePredicate Text Bool) where
237+ joinPreds p (Predicates x y) = Predicates x (go <> y)
238+ where go = let p' = first return p
239+ in fmap (\z -> if z then [] else respPredName p') p'
422240
423−instance JoinPreds (ResponsePredicate ) where
424− joinPreds p (Predicates x y) = Predicates x (p <> y)
425241
426242-- | Adds a new predicate (either `ResponsePredicate` or `RequestPredicate`) to
427243-- the existing predicates.
428244--
429245-- > not500 <%> onlyJsonObjects <%> empty
430−--
431−-- /Since 0.0.0.0/
432−(<%>) :: JoinPreds a => a -> Predicates -> Predicates
246+(<%>) :: JoinPreds a => a -> Predicates [Text] [Text] -> Predicates [Text] [Text]
433247(<%>) = joinPreds
434248infixr 6 <%>
435249
436−finishPredicates :: Predicates -> Request -> Manager -> IO (Maybe PredicateFailure)
437−finishPredicates p req mgr = go `catch` \(e :: PredicateFailure) -> return $ Just e
438− where
439− go = do
440− resps <- getRequestPredicate (requestPredicates p) req mgr
441− mapM_ (getResponsePredicate $ responsePredicates p) resps
442− return Nothing
250+finishPredicates :: Predicates [Text] [Text] -> Request -> Manager -> IO [Text]
251+finishPredicates p req mgr = do
252+ resps <- reqResps (reqPreds p) req mgr
253+ let preds = reqPred (reqPreds p) <> respPreds p
254+ return $ mconcat [respPred preds r | r <- resps ]
443255
444256-- * helpers
445257
@@ -447,15 +259,3 @@ hasValidHeader :: SBS.ByteString -> (SBS.ByteString -> Bool) -> Response b -> Bo
447259hasValidHeader hdr p r = case lookup (mk hdr) (responseHeaders r) of
448260 Nothing -> False
449261 Just v -> p v
450−
451−isRFC822Date :: SBS.ByteString -> Bool
452−isRFC822Date s
453− = case parseTimeM True defaultTimeLocale rfc822DateFormat (SBSC.unpack s) of
454− Nothing -> False
455− Just (_ :: UTCTime) -> True
456−
457−status2XX :: Monad m => Maybe Request -> Response LBS.ByteString -> T.Text -> m ()
458−status2XX mreq resp t
459− | status200 <= responseStatus resp && responseStatus resp < status300
460− = return ()
461− | otherwise = throw $ PredicateFailure t mreq resp