@@ -10,8 +10,9 @@ import Blaze.ByteString.Builder
1010import Control.Concurrent.Async
1111import Control.Exception hiding (assert )
1212import Control.Monad (forM_ , when , unless )
13- import Control.Monad.Trans.Resource
13+ import Control.Monad.Trans.Resource ( runResourceT )
1414import Data.ByteString (ByteString )
15+ import Data.Conduit (ConduitT , Flush (.. ), SealedConduitT )
1516import Data.Int (Int64 )
1617import Data.Maybe
1718import Data.String (fromString )
@@ -156,14 +157,14 @@ httpRun req = do
156157 runResourceT $ do
157158 resp <- HC. http (modifyRequest req) mgr
158159 let contentLen = readInt64 <$> lookup HT. hContentLength (HC. responseHeaders resp)
159- bodyText <- checkBodySize (HC. responseBody resp) contentLen
160+ bodyText <- checkBodySize (DC. sealConduitT $ HC. responseBody resp) contentLen
160161 return $ Result (HC. secure req) (HT. statusCode $ HC. responseStatus resp)
161162 (HC. responseHeaders resp) bodyText
162163 where
163164 modifyRequest r = r { HC. redirectCount = 0 }
164165
165166
166- checkBodySize :: ( Monad f , Functor f ) => DC. ResumableSource f ByteString -> Maybe Int64 -> f ByteString
167+ checkBodySize :: Monad f => SealedConduitT () ByteString f () -> Maybe Int64 -> f ByteString
167168checkBodySize bodySrc Nothing = fmap (BS. concat . LBS. toChunks) $ bodySrc DC. $$+- CB. take 1000
168169checkBodySize bodySrc (Just len) = do
169170 let blockSize = 1000
@@ -172,13 +173,13 @@ checkBodySize bodySrc (Just len) = do
172173 else fromMaybe " Success" <$> (bodySrc DC. $$+- byteSink len)
173174
174175
175- byteSink :: Monad m => Int64 -> DC. Sink ByteString m (Maybe ByteString )
176+ byteSink :: Monad m => Int64 -> ConduitT ByteString a m (Maybe ByteString )
176177byteSink bytes = sink 0
177178 where
178- sink :: Monad m => Int64 -> DC. Sink ByteString m (Maybe ByteString )
179+ sink :: Monad m => Int64 -> ConduitT ByteString a m (Maybe ByteString )
179180 sink ! count = DC. await >>= maybe (closeSink count) (sinkBlock count)
180181
181- sinkBlock :: Monad m => Int64 -> ByteString -> DC. Sink ByteString m (Maybe ByteString )
182+ sinkBlock :: Monad m => Int64 -> ByteString -> ConduitT ByteString a m (Maybe ByteString )
182183 sinkBlock ! count bs = sink (count + fromIntegral (BS. length bs))
183184
184185 closeSink :: Monad m => Int64 -> m (Maybe ByteString )
@@ -189,14 +190,14 @@ byteSink bytes = sink 0
189190 ++ " should have been " ++ show bytes ++ " ."
190191
191192
192- builderSource :: Monad m => Int64 -> DC. Source m ( DC. Flush Builder )
193- builderSource = DC. mapOutput (DC. Chunk . fromByteString) . byteSource
193+ builderSource :: Monad m => Int64 -> ConduitT () ( Flush Builder ) m ( )
194+ builderSource = DC. mapOutput (Chunk . fromByteString) . byteSource
194195
195196
196- byteSource :: Monad m => Int64 -> DC. Source m ByteString
197+ byteSource :: Monad m => Int64 -> ConduitT i ByteString m ()
197198byteSource bytes = loop 0
198199 where
199- loop :: Monad m => Int64 -> DC. Source m ByteString
200+ loop :: Monad m => Int64 -> ConduitT i ByteString m ()
200201 loop ! count
201202 | count >= bytes = return ()
202203 | count + blockSize64 < bytes = do
@@ -205,7 +206,7 @@ byteSource bytes = loop 0
205206 | otherwise = do
206207 let n = fromIntegral $ bytes - count
207208 DC. yield $ BS. take n bsbytes
208- return ()
209+ pure ()
209210
210211 blockSize = 8192 :: Int
211212 blockSize64 = fromIntegral blockSize :: Int64
0 commit comments