wai 0.0.0 → 0.0.1
raw patch · 2 files changed
+34/−7 lines, 2 files
Files
- Network/Wai/Enumerator.hs +28/−5
- wai.cabal +6/−2
Network/Wai/Enumerator.hs view
@@ -15,6 +15,8 @@ -- ** FilePath , fromFile , fromEitherFile+ -- * Filters+ , buffer ) where import Network.Wai (Enumerator (..), Source (..))@@ -67,16 +69,16 @@ -- deadlocked. toSource :: Enumerator -> IO Source toSource (Enumerator e) = do- buffer <- newEmptyMVar- _ <- forkIO $ e (helper buffer) () >> putMVar buffer Nothing- return $ source buffer+ buff <- newEmptyMVar+ _ <- forkIO $ e (helper buff) () >> putMVar buff Nothing+ return $ source buff where helper :: MVar (Maybe B.ByteString) -> () -> B.ByteString -> IO (Either () ())- helper buffer _ bs = do- putMVar buffer $ Just bs+ helper buff _ bs = do+ putMVar buff $ Just bs return $ Right () source :: MVar (Maybe B.ByteString) -> Source@@ -115,3 +117,24 @@ -- be convenient for server implementations not optimizing file sending. fromEitherFile :: Either FilePath Enumerator -> Enumerator fromEitherFile = either fromFile id++-- | Buffer chunks until we have a chunk of 'defaultChunkSize', and then send+-- it.+buffer :: Enumerator -> Enumerator+buffer (Enumerator e) =+ Enumerator go+ where+ go iter seed = do+ res <- e (iter' iter) (B.empty, seed)+ case res of+ Left (_, seed') -> return $ Left seed'+ Right (buff, seed') -> iter seed' buff+ iter' iter (buff, seed) bs = do+ if B.length buff + B.length bs < defaultChunkSize+ then return $ Right (buff `B.append` bs, seed)+ else do+ let (x, y) = B.splitAt (defaultChunkSize - B.length buff) bs+ res <- iter seed $ buff `B.append` x+ case res of+ Left seed' -> return $ Left (y, seed') -- y is ignored+ Right seed' -> return $ Right (y, seed')
wai.cabal view
@@ -1,5 +1,5 @@ Name: wai-Version: 0.0.0+Version: 0.0.1 Synopsis: Web Application Interface. Description: Provides a common protocol for communication between web aplications and web servers. License: BSD3@@ -9,8 +9,12 @@ Homepage: http://github.com/snoyberg/wai Category: Web Build-Type: Simple-Cabal-Version: >=1.2+Cabal-Version: >=1.6 Stability: Stable++Source-repository head+ type: git+ location: git://github.com/snoyberg/wai.git Library Build-Depends: base >= 3 && < 5,