@@ -1,6 +1,6 @@
11module Servant.QuickCheck.Internal.Predicates where
22
3−import Control.Monad
3+import Control.Monad (liftM2)
44import Data.Aeson (Object, decode)
55import Data.Bifunctor (Bifunctor (..))
66import qualified Data.ByteString as SBS
@@ -9,7 +9,7 @@ import qualified Data.ByteString.Lazy as LBS
99import Data.CaseInsensitive (mk)
1010import Data.Either (isRight)
1111import Data.List.Split (wordsBy)
12−import Data.Maybe (fromMaybe, isJust, maybeToList)
12+import Data.Maybe (fromMaybe, isJust)
1313import Data.Monoid ((<>))
1414import Data.Text (Text)
1515import GHC.Generics (Generic)
@@ -21,7 +21,7 @@ import Network.HTTP.Media (matchAccept)
2121import Network.HTTP.Types (methodGet, methodHead, parseMethod,
2222 renderStdMethod, status200, status201,
2323 status300, status401, status405,
24− status500)
24+ status500, status100)
2525
2626-- | [__Best Practice__]
2727--
@@ -129,6 +129,7 @@ notAllowedContainsAllowHeader
129129 go x = all (\y -> isRight $ parseMethod $ SBSC.pack y)
130130 $ wordsBy (`elem` (", " :: [Char])) (SBSC.unpack x)
131131
132+
132133-- | [__RFC Compliance__]
133134--
134135-- When a request contains an @Accept@ header, the server must either return
@@ -136,12 +137,13 @@ notAllowedContainsAllowHeader
136137-- Acceptable@.
137138--
138139-- 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.
140142--
141143-- __References__:
142144--
143145-- * @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
145147honoursAcceptHeader
146148 = RequestPredicate
147149 { reqPredName = "honoursAcceptHeader"
@@ -150,8 +152,8 @@ honoursAcceptHeader
150152 let scode = responseStatus resp
151153 sctype = lookup "Content-Type" $ responseHeaders resp
152154 sacc = fromMaybe "*/*" $ lookup "Accept" (requestHeaders req)
153− if 100 < scode && scode < 300
154− then return (isJust $ sctype >>= \x -> matchAccept x sacc, [resp])
155+ if status100 < scode && scode < status300
156+ then return (isJust $ sctype >>= \x -> matchAccept [x] sacc, [resp])
155157 else return (True, [resp])
156158 }
157159