@@ -31,6 +31,8 @@ import Network.HTTP.Types (methodGet, methodHead, parseMethod,
3131-- indication of how to proceed or what went wrong.
3232--
3333-- This function checks that the response code is not 500.
34+--
35+-- /Since 0.0.0.0/
3436not500 :: ResponsePredicate Text Bool
3537not500 = ResponsePredicate "not500" (\resp -> not $ responseStatus resp == status500)
3638
@@ -53,6 +55,8 @@ not500 = ResponsePredicate "not500" (\resp -> not $ responseStatus resp == statu
5355--
5456-- * JSON Grammar: <https://tools.ietf.org/html/rfc7159#section-2 RFC 7159 Section 2>
5557-- * JSON Grammar: <https://tools.ietf.org/html/rfc4627#section-2 RFC 4627 Section 2>
58+--
59+-- /Since 0.0.0.0/
5660onlyJsonObjects :: ResponsePredicate Text Bool
5761onlyJsonObjects
5862 = ResponsePredicate "onlyJsonObjects" (\resp -> case decode (responseBody resp) of
@@ -76,6 +80,8 @@ onlyJsonObjects
7680--
7781-- * 201 Created: <https://tools.ietf.org/html/rfc7231#section-6.3.2 RFC 7231 Section 6.3.2>
7882-- * Location header: <https://tools.ietf.org/html/rfc7231#section-7.1.2 RFC 7231 Section 7.1.2>
83+--
84+-- /Since 0.0.0.0/
7985createContainsValidLocation :: RequestPredicate Text Bool
8086createContainsValidLocation
8187 = RequestPredicate
@@ -114,6 +120,8 @@ getsHaveLastModifiedHeader
114120--
115121-- * @Allow@ header: <https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html RFC 2616 Section 14.7>
116122-- * Status 405: <https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html RFC 2616 Section 10.4.6>
123+--
124+-- /Since 0.0.0.0/
117125notAllowedContainsAllowHeader :: RequestPredicate Text Bool
118126notAllowedContainsAllowHeader
119127 = RequestPredicate
@@ -144,6 +152,8 @@ notAllowedContainsAllowHeader
144152-- __References__:
145153--
146154-- * @Accept@ header: <https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html RFC 2616 Section 14.1>
155+--
156+-- /Since 0.0.0.0/
147157honoursAcceptHeader :: RequestPredicate Text Bool
148158honoursAcceptHeader
149159 = RequestPredicate
@@ -171,7 +181,7 @@ honoursAcceptHeader
171181--
172182-- * @Cache-Control@ header: <https://tools.ietf.org/html/rfc7234#section-5.2 RFC 7234 Section 5.2>
173183--
174−-- #SINCE#
184+-- /Since 0.0.0.0/
175185getsHaveCacheControlHeader :: RequestPredicate Text Bool
176186getsHaveCacheControlHeader
177187 = RequestPredicate
@@ -188,7 +198,7 @@ getsHaveCacheControlHeader
188198--
189199-- Like 'getsHaveCacheControlHeader', but for @HEAD@ requests.
190200--
191−-- #SINCE#
201+-- /Since 0.0.0.0/
192202headsHaveCacheControlHeader :: RequestPredicate Text Bool
193203headsHaveCacheControlHeader
194204 = RequestPredicate
@@ -260,7 +270,7 @@ linkHeadersAreValid
260270--
261271-- * @WWW-Authenticate@ header: <https://tools.ietf.org/html/rfc7235#section-4.1 RFC 7235 Section 4.1>
262272--
263−-- #SINCE#
273+-- /Since 0.0.0.0/
264274unauthorizedContainsWWWAuthenticate :: ResponsePredicate Text Bool
265275unauthorizedContainsWWWAuthenticate
266276 = ResponsePredicate "unauthorizedContainsWWWAuthenticate" (\resp ->
@@ -276,6 +286,9 @@ unauthorizedContainsWWWAuthenticate
276286--
277287-- Still, this is all kind of ugly.
278288
289+-- | A predicate that depends only on the response.
290+--
291+-- /Since 0.0.0.0/
279292data ResponsePredicate n r = ResponsePredicate
280293 { respPredName :: n
281294 , respPred :: Response LBS.ByteString -> r
@@ -292,6 +305,9 @@ instance (Monoid n, Monoid r) => Monoid (ResponsePredicate n r) where
292305 , respPred = respPred a <> respPred b
293306 }
294307
308+-- | A predicate that depends on both the request and the response.
309+--
310+-- /Since 0.0.0.0/
295311data RequestPredicate n r = RequestPredicate
296312 { reqPredName :: n
297313 , reqResps :: Request -> Manager -> IO (r, [Response LBS.ByteString])
@@ -309,6 +325,7 @@ instance (Monoid n, Monoid r) => Monoid (RequestPredicate n r) where
309325 , reqResps = \x m -> liftM2 (<>) (reqResps a x m) (reqResps b x m)
310326 }
311327
328+-- | A set of predicates. Construct one with 'mempty' and '<%>'.
312329data Predicates n r = Predicates
313330 { reqPreds :: RequestPredicate n r
314331 , respPreds :: ResponsePredicate n r
@@ -339,7 +356,7 @@ instance JoinPreds (ResponsePredicate Text Bool) where
339356--
340357-- > not500 <%> onlyJsonObjects <%> empty
341358--
342−-- #SINCE#
359+-- /Since 0.0.0.0/
343360(<%>) :: JoinPreds a => a -> Predicates [Text] [Text] -> Predicates [Text] [Text]
344361(<%>) = joinPreds
345362infixr 6 <%>