@@ -1,6 +1,6 @@
1module Servant.QuickCheck.Internal.Predicates where
1module Servant.QuickCheck.Internal.Predicates where
3−import Control.Monad
3+import Control.Monad (liftM2)
4import Data.Aeson (Object, decode)
4import Data.Aeson (Object, decode)
5import Data.Bifunctor (Bifunctor (..))
5import Data.Bifunctor (Bifunctor (..))
6import qualified Data.ByteString as SBS
6import qualified Data.ByteString as SBS
@@ -9,7 +9,7 @@ import qualified Data.ByteString.Lazy as LBS
9import Data.CaseInsensitive (mk)
9import Data.CaseInsensitive (mk)
10import Data.Either (isRight)
10import Data.Either (isRight)
11import Data.List.Split (wordsBy)
11import Data.List.Split (wordsBy)
12−import Data.Maybe (fromMaybe, isJust, maybeToList)
12+import Data.Maybe (fromMaybe, isJust)
13import Data.Monoid ((<>))
13import Data.Monoid ((<>))
14import Data.Text (Text)
14import Data.Text (Text)
15import GHC.Generics (Generic)
15import GHC.Generics (Generic)
@@ -21,7 +21,7 @@ import Network.HTTP.Media (matchAccept)
21import Network.HTTP.Types (methodGet, methodHead, parseMethod,
21import Network.HTTP.Types (methodGet, methodHead, parseMethod,
22 renderStdMethod, status200, status201,
22 renderStdMethod, status200, status201,
23 status300, status401, status405,
23 status300, status401, status405,
24− status500)
24+ status500, status100)
26-- | [__Best Practice__]
26-- | [__Best Practice__]
@@ -129,6 +129,7 @@ notAllowedContainsAllowHeader
129 go x = all (\y -> isRight $ parseMethod $ SBSC.pack y)
129 go x = all (\y -> isRight $ parseMethod $ SBSC.pack y)
130 $ wordsBy (`elem` (", " :: [Char])) (SBSC.unpack x)
130 $ wordsBy (`elem` (", " :: [Char])) (SBSC.unpack x)
132-- | [__RFC Compliance__]
133-- | [__RFC Compliance__]
134-- When a request contains an @Accept@ header, the server must either return
135-- When a request contains an @Accept@ header, the server must either return
@@ -136,12 +137,13 @@ notAllowedContainsAllowHeader
136-- Acceptable@.
137-- Acceptable@.
138-- This function checks that every *successful* response has a @Content-Type@
139-- This function checks that every *successful* response has a @Content-Type@
139−-- header that matches the @Accept@ header.
140+-- header that matches the @Accept@ header. It does *not* check that the server
141+-- matches the quality descriptions of the @Accept@ header correctly.
141-- __References__:
143-- __References__:
143-- * @Accept@ header: <https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html RFC 2616 Section 14.1>
145-- * @Accept@ header: <https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html RFC 2616 Section 14.1>
144−honoursAcceptHeader :: RequestPredicate b Bool
146+honoursAcceptHeader :: RequestPredicate Text Bool
145honoursAcceptHeader
147honoursAcceptHeader
146 = RequestPredicate
148 = RequestPredicate
147 { reqPredName = "honoursAcceptHeader"
149 { reqPredName = "honoursAcceptHeader"
@@ -150,8 +152,8 @@ honoursAcceptHeader
150 let scode = responseStatus resp
152 let scode = responseStatus resp
151 sctype = lookup "Content-Type" $ responseHeaders resp
153 sctype = lookup "Content-Type" $ responseHeaders resp
152 sacc = fromMaybe "*/*" $ lookup "Accept" (requestHeaders req)
154 sacc = fromMaybe "*/*" $ lookup "Accept" (requestHeaders req)
153− if 100 < scode && scode < 300
155+ if status100 < scode && scode < status300
154− then return (isJust $ sctype >>= \x -> matchAccept x sacc, [resp])
156+ then return (isJust $ sctype >>= \x -> matchAccept [x] sacc, [resp])
155 else return (True, [resp])
157 else return (True, [resp])