git.iko.soy/typeable/servant
on master help sign in
Update request content-type handling
92f8d23Giovanni Cappellotto
servant-server/src/Servant/Server/Internal.hs+1−1
@@ -603,7 +603,7 @@ instance ( AllCTUnrender list a, HasServer api context, SBoolI (FoldLenient mods
603 let contentTypeH = fromMaybe "application/octet-stream"
603 let contentTypeH = fromMaybe "application/octet-stream"
604 $ lookup hContentType $ requestHeaders request
604 $ lookup hContentType $ requestHeaders request
605 case canHandleCTypeH (Proxy :: Proxy list) (cs contentTypeH) :: Maybe (BL.ByteString -> Either String a) of
605 case canHandleCTypeH (Proxy :: Proxy list) (cs contentTypeH) :: Maybe (BL.ByteString -> Either String a) of
606− Nothing -> delayedFailFatal err415
606+ Nothing -> delayedFail err415
607 Just f -> return f
607 Just f -> return f
608
608
609 -- Body check, we get a body parsing functions as the first argument.
609 -- Body check, we get a body parsing functions as the first argument.
servant-server/test/Servant/Server/ErrorSpec.hs+11−2
@@ -247,6 +247,8 @@ type ErrorChoiceApi
247 :<|> "path3" :> ReqBody '[JSON] Int :> Post '[PlainText] Int -- 3
247 :<|> "path3" :> ReqBody '[JSON] Int :> Post '[PlainText] Int -- 3
248 :<|> "path4" :> (ReqBody '[PlainText] Int :> Post '[PlainText] Int -- 4
248 :<|> "path4" :> (ReqBody '[PlainText] Int :> Post '[PlainText] Int -- 4
249 :<|> ReqBody '[PlainText] Int :> Post '[JSON] Int) -- 5
249 :<|> ReqBody '[PlainText] Int :> Post '[JSON] Int) -- 5
250+ :<|> "path5" :> (ReqBody '[JSON] Int :> Post '[PlainText] Int -- 6
251+ :<|> ReqBody '[PlainText] Int :> Post '[PlainText] Int) -- 7
250
252
251errorChoiceApi :: Proxy ErrorChoiceApi
253errorChoiceApi :: Proxy ErrorChoiceApi
252errorChoiceApi = Proxy
254errorChoiceApi = Proxy
@@ -256,8 +258,8 @@ errorChoiceServer = return 0
256 :<|> return 1
258 :<|> return 1
257 :<|> return 2
259 :<|> return 2
258 :<|> (\_ -> return 3)
260 :<|> (\_ -> return 3)
259− :<|> (\_ -> return 4)
261+ :<|> ((\_ -> return 4) :<|> (\_ -> return 5))
260− :<|> (\_ -> return 5)
262+ :<|> ((\_ -> return 6) :<|> (\_ -> return 7))
261
263
262
264
263errorChoiceSpec :: Spec
265errorChoiceSpec :: Spec
@@ -278,6 +280,13 @@ errorChoiceSpec = describe "Multiple handlers return errors"
278 request methodPost "path4" [(hContentType, "text/plain;charset=utf-8"),
280 request methodPost "path4" [(hContentType, "text/plain;charset=utf-8"),
279 (hAccept, "blah")] "5"
281 (hAccept, "blah")] "5"
280 `shouldRespondWith` 406
282 `shouldRespondWith` 406
283+ it "should respond with 415 only if none of the subservers supports the request's content type" $ do
284+ request methodPost "path5" [(hContentType, "text/plain;charset=utf-8")] "1"
285+ `shouldRespondWith` 200
286+ request methodPost "path5" [(hContentType, "application/json")] "1"
287+ `shouldRespondWith` 200
288+ request methodPost "path5" [(hContentType, "application/not-supported")] ""
289+ `shouldRespondWith` 415
281
290
282
291
283-- }}}
292-- }}}