1
module Network.Wai.Handler.Helper
6
import System.IO (Handle)
7
import qualified Data.ByteString as B
8
import Data.ByteString.Lazy.Internal (defaultChunkSize)
9
import Network.Wai (Source (..))
11
requestBodyHandle :: Handle -> Int -> Source
15
go i = Just `fmap` B.hGet h (min i defaultChunkSize)
17
requestBodyFunc :: (Int -> IO (Maybe B.ByteString)) -> Int -> Source
18
requestBodyFunc _ 0 = Source $ return Nothing
19
requestBodyFunc h len = Source $ do
22
Nothing -> return Nothing
24
let newLen = len - B.length bs
25
return $ Just (bs, requestBodyFunc h $ max 0 newLen)