Skip to content

Commit 761443f

Browse files
committed
Merge pull request #357 from haskell-servant/jkarni/remove-memoReqBody
Remove memoReqBody.
2 parents 2ae5041 + 3bd3eff commit 761443f

File tree

3 files changed

+6
-28
lines changed

3 files changed

+6
-28
lines changed

servant-server/src/Servant/Server/Internal.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ methodCheck method request
158158
acceptCheck :: (AllMime list) => Proxy list -> B.ByteString -> IO (RouteResult ())
159159
acceptCheck proxy accH
160160
| canHandleAcceptH proxy (AcceptHeader accH) = return $ Route ()
161-
| otherwise = return $ Fail err406
161+
| otherwise = return $ FailFatal err406
162162

163163
methodRouter :: (AllCTRender ctypes a)
164164
=> Method -> Proxy ctypes -> Status

servant-server/src/Servant/Server/Internal/RoutingApplication.hs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
4036
toApplication :: 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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {{{

0 commit comments

Comments
 (0)