git.iko.soy/typeable/servant
on master help sign in
Merge pull request #357 from haskell-servant/jkarni/remove-memoReqBody

Remove memoReqBody.

commit761443fffecbe83aa408d5f705dd0a8dade08af9 authorJulian Arni <jkarni@gmail.com> dateFri 5 Feb 2016, 20:05 (11 years ago) parent2ae50413bd3eff
3 files changed+6−28
servant-server/src/Servant/Server/Internal.hs+1−1 servant-server/src/Servant/Server/Internal/RoutingApplication.hs+1−27 servant-server/test/Servant/Server/ErrorSpec.hs+4
servant-server/src/Servant/Server/Internal.hs+1−1
@@ -158,7 +158,7 @@ methodCheck method request
158158acceptCheck :: (AllMime list) => Proxy list -> B.ByteString -> IO (RouteResult ())
159159acceptCheck proxy accH
160160 | canHandleAcceptH proxy (AcceptHeader accH) = return $ Route ()
161− | otherwise = return $ Fail err406
161+ | otherwise = return $ FailFatal err406
162162
163163methodRouter :: (AllCTRender ctypes a)
164164 => Method -> Proxy ctypes -> Status
servant-server/src/Servant/Server/Internal/RoutingApplication.hs+1−27
@@ -33,34 +33,8 @@ data RouteResult a =
3333 | Route !a
3434 deriving (Eq, Show, Read, Functor)
3535
36−data ReqBodyState = Uncalled
37− | Called !B.ByteString
38− | Done !B.ByteString
39−
4036toApplication :: RoutingApplication -> Application
41−toApplication ra request respond = do
42− reqBodyRef <- newIORef Uncalled
43− -- We may need to consume the requestBody more than once. In order to
44− -- maintain the illusion that 'requestBody' works as expected,
45− -- 'ReqBodyState' is introduced, and the complete body is memoized and
46− -- returned as many times as requested with empty "Done" marker chunks in
47− -- between.
48− -- See https://github.com/haskell-servant/servant/issues/3
49− let memoReqBody = do
50− ior <- readIORef reqBodyRef
51− case ior of
52− Uncalled -> do
53− r <- BL.toStrict <$> strictRequestBody request
54− writeIORef reqBodyRef $ Done r
55− return r
56− Called bs -> do
57− writeIORef reqBodyRef $ Done bs
58− return bs
59− Done bs -> do
60− writeIORef reqBodyRef $ Called bs
61− return B.empty
62−
63− ra request{ requestBody = memoReqBody } routingRespond
37+toApplication ra request respond = ra request routingRespond
6438 where
6539 routingRespond :: RouteResult Response -> IO ResponseReceived
6640 routingRespond (Fail err) = respond $ responseServantErr err
servant-server/test/Servant/Server/ErrorSpec.hs+4
@@ -168,6 +168,10 @@ errorRetrySpec = describe "Handler search"
168168 request methodGet "a" [jsonCT, jsonAccept] jsonBody
169169 `shouldRespondWith` 200 { matchBody = Just $ encode (4 :: Int) }
170170
171+ it "should not continue when body cannot be decoded" $ do
172+ request methodPost "a" [jsonCT, jsonAccept] "a string"
173+ `shouldRespondWith` 400
174+
171175-- }}}
172176------------------------------------------------------------------------------
173177-- * Error Choice {{{