packages feed

quiver-http 0.0.0.1 → 0.0.0.2

raw patch · 2 files changed

+23/−9 lines, 2 filesdep ~quiver

Dependency ranges changed: quiver

Files

quiver-http.cabal view
@@ -1,8 +1,8 @@ name:           quiver-http-version:        0.0.0.1+version:        0.0.0.2 synopsis:       Adapter to stream over HTTP(s) with quiver homepage:       https://github.com/christian-marie/quiver-http/-category:       Utility+category:       Control, HTTP stability:      alpha  author:         Christian Marie <christian@ponies.io>
src/Control/Quiver/HTTP.hs view
@@ -77,7 +77,8 @@ import           Control.Quiver import           Control.Quiver.Internal import           Data.ByteString         (ByteString)-import qualified Data.ByteString         as B+import qualified Data.ByteString         as S+import qualified Data.ByteString.Lazy    as L import           Data.Int                (Int64) import           Data.IORef              (newIORef, readIORef, writeIORef) import           Network.HTTP.Client@@ -102,12 +103,27 @@         runEffect (loop br >->> k scrubbed_resp >&> snd)      loop br = do-        bs <- qlift (brRead br)-        unless (B.null bs) $ do+        bs <- qlift (L.toStrict <$> brReadSome' br chunkSize)+        unless (S.null bs) $ do             emit_ bs             loop br-        deliver () +    -- Minimum chunk size to emit, set to some reasonable page size+    chunkSize = 4096++-- Stolen from the internals of http-client+brReadSome' :: IO ByteString -> Int -> IO L.ByteString+brReadSome' brRead' =+    loop id+  where+    loop front remainder+        | remainder <= 0 = return $ L.fromChunks $ front []+        | otherwise = do+            bs <- brRead'+            if S.null bs+                then return $ L.fromChunks $ front []+                else loop (front . (bs:)) (remainder - S.length bs)+ -- | Build a 'RequestBody' by chunked transfer encoding a 'Producer'. -- -- Each 'ByteString' produced will be sent as a seperate chunk.@@ -127,8 +143,6 @@ -- In summary, we take a Producer and turn it into a function which: given a -- continuation which takes an IO action that -- when called, will produce -- successive chunks -- returns an IO () and does some super strange things.------ Gabriel worked this out in pipes-http, and this works. Thanks Gabriel. givePopper     :: Producer ByteString () IO ()     -> (IO ByteString -> IO ())@@ -143,7 +157,7 @@         case x of             Left () -> do                 writeIORef ref (return ())-                return B.empty+                return S.empty             Right (bs, next_producer) -> do                 writeIORef ref next_producer                 return bs