http-client-conduit-0.2.0.0/0000755000000000000000000000000012247525235013742 5ustar0000000000000000http-client-conduit-0.2.0.0/Setup.hs0000644000000000000000000000005612247525235015377 0ustar0000000000000000import Distribution.Simple main = defaultMain http-client-conduit-0.2.0.0/http-client-conduit.cabal0000644000000000000000000000146312247525235020630 0ustar0000000000000000name: http-client-conduit version: 0.2.0.0 synopsis: Frontend support for using http-client with conduit description: Intended for use by higher-level libraries, such as http-conduit. homepage: https://github.com/snoyberg/http-client license: MIT license-file: LICENSE author: Michael Snoyman maintainer: michael@snoyman.com category: Network build-type: Simple cabal-version: >=1.10 library exposed-modules: Network.HTTP.Client.Conduit build-depends: base >= 4 && < 5 , http-client >= 0.2 , conduit , resourcet , bytestring , transformers default-language: Haskell2010 http-client-conduit-0.2.0.0/LICENSE0000644000000000000000000000207212247525235014750 0ustar0000000000000000The MIT License (MIT) Copyright (c) 2013 Michael Snoyman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. http-client-conduit-0.2.0.0/Network/0000755000000000000000000000000012247525235015373 5ustar0000000000000000http-client-conduit-0.2.0.0/Network/HTTP/0000755000000000000000000000000012247525235016152 5ustar0000000000000000http-client-conduit-0.2.0.0/Network/HTTP/Client/0000755000000000000000000000000012247525235017370 5ustar0000000000000000http-client-conduit-0.2.0.0/Network/HTTP/Client/Conduit.hs0000644000000000000000000000562512247525235021341 0ustar0000000000000000{-# LANGUAGE RankNTypes #-} -- | Frontend support for using http-client with conduit. Intended for use with -- higher-level libraries like http-conduit. module Network.HTTP.Client.Conduit ( requestBodySource , requestBodySourceChunked , requestBodySourceIO , requestBodySourceChunkedIO , bodyReaderSource , http ) where import Data.Conduit import qualified Data.Conduit.Internal as CI import Control.Monad.Trans.Resource import Network.HTTP.Client import Network.HTTP.Client.Internal import Data.Int (Int64) import qualified Data.ByteString as S import Data.ByteString (ByteString) import Data.IORef import Control.Monad.IO.Class (MonadIO, liftIO) import Control.Monad (unless) bodyReaderSource :: MonadIO m => BodyReader -> Producer m ByteString bodyReaderSource br = loop where loop = do bs <- liftIO $ brRead br unless (S.null bs) $ do yield bs loop http :: MonadResource m => Request -> Manager -> m (Response (ResumableSource m ByteString)) http req man = do (key, res) <- allocate (responseOpen req man) responseClose let rsrc = CI.ResumableSource (bodyReaderSource $ responseBody res) (release key) return res { responseBody = rsrc } requestBodySource :: Int64 -> Source (ResourceT IO) ByteString -> RequestBody requestBodySource size = RequestBodyStream size . srcToPopper requestBodySourceChunked :: Source (ResourceT IO) ByteString -> RequestBody requestBodySourceChunked = RequestBodyStreamChunked . srcToPopper srcToPopper :: Source (ResourceT IO) ByteString -> GivesPopper () srcToPopper src f = runResourceT $ do (rsrc0, ()) <- src $$+ return () irsrc <- liftIO $ newIORef rsrc0 is <- getInternalState let popper :: IO ByteString popper = do rsrc <- readIORef irsrc (rsrc', mres) <- runInternalState (rsrc $$++ await) is writeIORef irsrc rsrc' case mres of Nothing -> return S.empty Just bs | S.null bs -> popper | otherwise -> return bs liftIO $ f popper requestBodySourceIO :: Int64 -> Source IO ByteString -> RequestBody requestBodySourceIO size = RequestBodyStream size . srcToPopperIO requestBodySourceChunkedIO :: Source IO ByteString -> RequestBody requestBodySourceChunkedIO = RequestBodyStreamChunked . srcToPopperIO srcToPopperIO :: Source IO ByteString -> GivesPopper () srcToPopperIO src f = do (rsrc0, ()) <- src $$+ return () irsrc <- newIORef rsrc0 let popper :: IO ByteString popper = do rsrc <- readIORef irsrc (rsrc', mres) <- rsrc $$++ await writeIORef irsrc rsrc' case mres of Nothing -> return S.empty Just bs | S.null bs -> popper | otherwise -> return bs f popper