@@ -1,22 +1,28 @@
1+{-# LANGUAGE MultiWayIf #-}
12module Servant.QuickCheck.Internal.Predicates where
23
34import 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
5+import Data.Aeson (Object, decode)
6+import Data.Bifunctor (Bifunctor (..))
7+import qualified Data.ByteString as SBS
88import qualified Data.ByteString.Char8 as SBSC
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, status401, parseMethod)
18−
19−-- | @500 Internal Server Error@ should be avoided - it may represent some
9+import qualified Data.ByteString.Lazy as LBS
10+import Data.CaseInsensitive (mk)
11+import Data.Either (isRight)
12+import Data.List.Split (wordsBy)
13+import Data.Maybe (isJust)
14+import Data.Monoid ((<>))
15+import Data.Text (Text)
16+import GHC.Generics (Generic)
17+import Network.HTTP.Client (Manager, Request, Response, httpLbs,
18+ method, responseBody, responseHeaders,
19+ responseStatus)
20+import Network.HTTP.Types (methodGet, methodHead, parseMethod,
21+ status401, renderStdMethod, status405, status500)
22+
23+-- | [__Best Practice__]
24+--
25+-- @500 Internal Server Error@ should be avoided - it may represent some
2026-- issue with the application code, and it moreover gives the client little
2127-- indication of how to proceed or what went wrong.
2228--
@@ -24,7 +30,9 @@ import Network.HTTP.Types (status500, status405, status401, parseMet
2430not500 :: ResponsePredicate Text Bool
2531not500 = ResponsePredicate "not500" (\resp -> not $ responseStatus resp == status500)
2632
27−-- | Returning anything other than an object when returning JSON is considered
33+-- | [__Best Practice__]
34+--
35+-- Returning anything other than an object when returning JSON is considered
2836-- bad practice, as:
2937--
3038-- (1) it is hard to modify the returned value while maintaining backwards
@@ -66,8 +74,11 @@ getsHaveLastModifiedHeader
6674
6775-}
6876
69−-- | When an HTTP request has a method that is not allowed, a 405 response
70−-- should be returned. Additionally, it is good practice to return an @Allow@
77+-- | [__RFC Compliance__]
78+--
79+-- When an HTTP request has a method that is not allowed,
80+-- a 405 response should be returned. Additionally, it is good practice to
81+-- return an @Allow@
7182-- header with the list of allowed methods.
7283--
7384-- This function checks that every @405 Method Not Allowed@ response contains
@@ -163,7 +174,9 @@ linkHeadersAreValid
163174 = ResponsePredicate "linkHeadersAreValid" _
164175
165176-}
166−-- | Any @401 Unauthorized@ response must include a @WWW-Authenticate@ header.
177+-- | [__RFC Compliance__]
178+--
179+-- Any @401 Unauthorized@ response must include a @WWW-Authenticate@ header.
167180--
168181-- This function checks that, if a response has status code 401, it contains a
169182-- @WWW-Authenticate@ header.