on master help sign in
Fix devel logger behavior for consistency
commit4f76770ff24460ded2319f26e1351c3ba372b5d4 authorMichael Snoyman <michael@snoyman.com> dateSun 8 Sep 2013, 16:59 (13 years ago) parent00d49d7
2 files changed+21−3
wai-extra/Network/Wai/Middleware/RequestLogger.hs+19−2 wai-extra/wai-extra.cabal+2−1
wai-extra/Network/Wai/Middleware/RequestLogger.hs+19−2
@@ -34,7 +34,7 @@ import qualified Data.Conduit as C
3434import qualified Data.Conduit.List as CL
3535
3636import System.Console.ANSI
37−import Data.IORef
37+import Data.IORef.Lifted
3838import System.IO.Unsafe
3939
4040import Data.Default (Default (def))
@@ -198,7 +198,24 @@ detailedMiddleware' cb getAddColor app req = do
198198 body <- requestBody req C.$$ CL.consume
199199 -- logging the body here consumes it, so fill it back up
200200 -- obviously not efficient, but this is the development logger
201− let req' = req { requestBody = CL.sourceList body }
201+ --
202+ -- Note: previously, we simply used CL.sourceList. However,
203+ -- that meant that you could read the request body in twice.
204+ -- While that in itself is not a problem, the issue is that,
205+ -- in production, you wouldn't be able to do this, and
206+ -- therefore some bugs wouldn't show up during testing. This
207+ -- implementation ensures that each chunk is only returned
208+ -- once.
209+ ichunks <- newIORef body
210+ let rbody = do
211+ chunks <- readIORef ichunks
212+ case chunks of
213+ [] -> return ()
214+ x:xs -> do
215+ writeIORef ichunks xs
216+ C.yield x
217+ rbody
218+ let req' = req { requestBody = rbody }
202219 return (req', body)
203220 _ -> return (req, [])
204221
wai-extra/wai-extra.cabal+2−1
@@ -1,5 +1,5 @@
11Name: wai-extra
2−Version: 1.3.4.4
2+Version: 1.3.4.5
33Synopsis: Provides some basic WAI handlers and middleware.
44Description: The goal here is to provide common features without many dependencies.
55License: MIT
@@ -46,6 +46,7 @@ Library
4646 , containers
4747 , base64-bytestring
4848 , word8
49+ , lifted-base
4950
5051 Exposed-modules: Network.Wai.Handler.CGI
5152 Network.Wai.Middleware.AcceptOverride