on master help sign in
Use the conduit producer branch
a031e67Michael Snoyman
.travis.yml+1−1
@@ -4,6 +4,6 @@ install:
4 - cabal unpack wai-logger-0.3.0
4 - cabal unpack wai-logger-0.3.0
5 - cp sources-travis.txt sources.txt
5 - cp sources-travis.txt sources.txt
6 - cabal install mega-sdist hspec cabal-meta cabal-src
6 - cabal install mega-sdist hspec cabal-meta cabal-src
7− - cabal-meta install
7+ - cabal-meta install --force-reinstalls
8
8
9script: mega-sdist --test
9script: mega-sdist --test
wai-extra/Network/Wai/Parse.hs+11−8
@@ -52,7 +52,7 @@ import Control.Monad (when, unless)
52import Control.Monad.Trans.Class (lift)
52import Control.Monad.Trans.Class (lift)
53import Control.Monad.Trans.Resource (allocate, release, register)
53import Control.Monad.Trans.Resource (allocate, release, register)
54#if MIN_VERSION_conduit(1, 0, 0)
54#if MIN_VERSION_conduit(1, 0, 0)
55−import Data.Conduit.Internal (Pipe (NeedInput, HaveOutput), (>+>), withUpstream, Sink (..), injectLeftovers, streamFromPipe, ConduitM)
55+import Data.Conduit.Internal (Pipe (NeedInput, HaveOutput), (>+>), withUpstream, Sink (..), injectLeftovers, ConduitM (..))
56import Data.Void (Void)
56import Data.Void (Void)
57#endif
57#endif
58
58
@@ -190,7 +190,7 @@ conduitRequestBody backend (Multipart bound) =
190 parsePieces backend $ S8.pack "--" `S.append` bound
190 parsePieces backend $ S8.pack "--" `S.append` bound
191
191
192#if MIN_VERSION_conduit(1, 0, 0)
192#if MIN_VERSION_conduit(1, 0, 0)
193−takeLine :: MonadSink S.ByteString m (Maybe S.ByteString)
193+takeLine :: Monad m => Consumer S.ByteString m (Maybe S.ByteString)
194#else
194#else
195takeLine :: Monad m => Pipe S.ByteString S.ByteString o u m (Maybe S.ByteString)
195takeLine :: Monad m => Pipe S.ByteString S.ByteString o u m (Maybe S.ByteString)
196#endif
196#endif
@@ -209,7 +209,7 @@ takeLine =
209 return $ Just $ killCR x
209 return $ Just $ killCR x
210
210
211#if MIN_VERSION_conduit(1, 0, 0)
211#if MIN_VERSION_conduit(1, 0, 0)
212−takeLines :: MonadSink S.ByteString (ResourceT IO) [S.ByteString]
212+takeLines :: Consumer S.ByteString (ResourceT IO) [S.ByteString]
213#else
213#else
214takeLines :: Pipe S.ByteString S.ByteString o u (ResourceT IO) [S.ByteString]
214takeLines :: Pipe S.ByteString S.ByteString o u (ResourceT IO) [S.ByteString]
215#endif
215#endif
@@ -311,13 +311,13 @@ sinkTillBound' :: S.ByteString
311#endif
311#endif
312sinkTillBound' bound name fi sink =
312sinkTillBound' bound name fi sink =
313#if MIN_VERSION_conduit(1, 0, 0)
313#if MIN_VERSION_conduit(1, 0, 0)
314− streamFromPipe $ anyOutput $
314+ ConduitM $ anyOutput $
315#endif
315#endif
316 conduitTillBound bound >+> withUpstream (fix $ sink name fi)
316 conduitTillBound bound >+> withUpstream (fix $ sink name fi)
317 where
317 where
318#if MIN_VERSION_conduit(1, 0, 0)
318#if MIN_VERSION_conduit(1, 0, 0)
319 fix :: Sink S8.ByteString (ResourceT IO) y -> Pipe Void S8.ByteString Void Bool (ResourceT IO) y
319 fix :: Sink S8.ByteString (ResourceT IO) y -> Pipe Void S8.ByteString Void Bool (ResourceT IO) y
320− fix (Sink p) = ignoreTerm >+> injectLeftovers p
320+ fix (ConduitM p) = ignoreTerm >+> injectLeftovers p
321 ignoreTerm = await' >>= maybe (return ()) (\x -> yield' x >> ignoreTerm)
321 ignoreTerm = await' >>= maybe (return ()) (\x -> yield' x >> ignoreTerm)
322 await' = NeedInput (return . Just) (const $ return Nothing)
322 await' = NeedInput (return . Just) (const $ return Nothing)
323 yield' = HaveOutput (return ()) (return ())
323 yield' = HaveOutput (return ()) (return ())
@@ -336,6 +336,9 @@ conduitTillBound :: Monad m
336 -> Pipe S.ByteString S.ByteString S.ByteString u m Bool
336 -> Pipe S.ByteString S.ByteString S.ByteString u m Bool
337#endif
337#endif
338conduitTillBound bound =
338conduitTillBound bound =
339+#if MIN_VERSION_conduit(1, 0, 0)
340+ unConduitM $
341+#endif
339 go id
342 go id
340 where
343 where
341 go front = await >>= maybe (close front) (push front)
344 go front = await >>= maybe (close front) (push front)
@@ -366,19 +369,19 @@ sinkTillBound :: S.ByteString
366 -> (x -> S.ByteString -> IO x)
369 -> (x -> S.ByteString -> IO x)
367 -> x
370 -> x
368#if MIN_VERSION_conduit(1, 0, 0)
371#if MIN_VERSION_conduit(1, 0, 0)
369− -> MonadSink S.ByteString (ResourceT IO) (Bool, x)
372+ -> Consumer S.ByteString (ResourceT IO) (Bool, x)
370#else
373#else
371 -> Pipe S.ByteString S.ByteString o u (ResourceT IO) (Bool, x)
374 -> Pipe S.ByteString S.ByteString o u (ResourceT IO) (Bool, x)
372#endif
375#endif
373sinkTillBound bound iter seed0 =
376sinkTillBound bound iter seed0 =
374#if MIN_VERSION_conduit(1, 0, 0)
377#if MIN_VERSION_conduit(1, 0, 0)
375− streamFromPipe $
378+ ConduitM $
376#endif
379#endif
377 (conduitTillBound bound >+> (withUpstream $ ij $ CL.foldM iter' seed0))
380 (conduitTillBound bound >+> (withUpstream $ ij $ CL.foldM iter' seed0))
378 where
381 where
379 iter' a b = liftIO $ iter a b
382 iter' a b = liftIO $ iter a b
380#if MIN_VERSION_conduit(1, 0, 0)
383#if MIN_VERSION_conduit(1, 0, 0)
381− ij p = ignoreTerm >+> injectLeftovers p
384+ ij (ConduitM p) = ignoreTerm >+> injectLeftovers p
382 ignoreTerm = await' >>= maybe (return ()) (\x -> yield' x >> ignoreTerm)
385 ignoreTerm = await' >>= maybe (return ()) (\x -> yield' x >> ignoreTerm)
383 await' = NeedInput (return . Just) (const $ return Nothing)
386 await' = NeedInput (return . Just) (const $ return Nothing)
384 yield' = HaveOutput (return ()) (return ())
387 yield' = HaveOutput (return ()) (return ())
warp/Network/Wai/Handler/Warp/Response.hs−10
@@ -1,6 +1,5 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE ScopedTypeVariables #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3−{-# LANGUAGE CPP #-}
4
3
5module Network.Wai.Handler.Warp.Response (
4module Network.Wai.Handler.Warp.Response (
6 sendResponse
5 sendResponse
@@ -15,9 +14,6 @@ import Data.ByteString (ByteString)
15import qualified Data.ByteString.Char8 as B (pack)
14import qualified Data.ByteString.Char8 as B (pack)
16import qualified Data.CaseInsensitive as CI
15import qualified Data.CaseInsensitive as CI
17import Data.Conduit
16import Data.Conduit
18−#if MIN_VERSION_conduit(1, 0, 0)
19−import Data.Conduit.Internal (mapOutput, SourceM (..))
20−#endif
21import Data.Conduit.Blaze (builderToByteString)
17import Data.Conduit.Blaze (builderToByteString)
22import qualified Data.Conduit.List as CL
18import qualified Data.Conduit.List as CL
23import Data.Maybe (isJust)
19import Data.Maybe (isJust)
@@ -111,15 +107,9 @@ sendResponse cleaner req conn (ResponseSource s hs bodyFlush)
111 where
107 where
112 th = threadHandle cleaner
108 th = threadHandle cleaner
113 body =
109 body =
114−#if MIN_VERSION_conduit(1, 0, 0)
115− SourceM $
116−#endif
117 mapOutput (\x -> case x of
110 mapOutput (\x -> case x of
118 Flush -> flush
111 Flush -> flush
119 Chunk builder -> builder)
112 Chunk builder -> builder)
120−#if MIN_VERSION_conduit(1, 0, 0)
121− $ unSourceM
122−#endif
123 bodyFlush
113 bodyFlush
124 cbody = if needsChunked then body $= chunk else body
114 cbody = if needsChunked then body $= chunk else body
125 -- FIXME perhaps alloca a buffer per thread and reuse that in all
115 -- FIXME perhaps alloca a buffer per thread and reuse that in all