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