git.iko.soy/servant-quickcheck
on master help sign in
Fix a bug in onlyJsonObjects that made it fail if there was no

content-type.

commit9743ac5ec44015851fdcf77b982f3fc1b636a817 authorJoachim Desroches <joachim.desroches@epfl.ch> dateFri 24 Aug 2018, 17:31 (8 years ago) parente3bf044
1 file changed+7−9
src/Servant/QuickCheck/Internal/Predicates.hs+7−9
src/Servant/QuickCheck/Internal/Predicates.hs+7−9
@@ -84,15 +84,13 @@ notLongerThan maxAllowed
8484-- /Since 0.0.0.0/
8585onlyJsonObjects :: ResponsePredicate
8686onlyJsonObjects
87− = ResponsePredicate (\resp -> case go resp of
88− Nothing -> throw $ PredicateFailure "onlyJsonObjects" Nothing resp
89− Just () -> return ())
90− where
91− go r = do
92− ctyp <- lookup "content-type" (first foldedCase <$> responseHeaders r)
93− when ("application/json" `SBS.isPrefixOf` ctyp) $ do
94− (_ :: Object) <- decode (responseBody r)
95− return ()
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 ())
9694
9795-- | __Optional__
9896--