summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog.md4
-rw-r--r--Network/HTTP/Client/Conduit.hs24
-rw-r--r--Network/HTTP/Conduit.hs1
-rw-r--r--Network/HTTP/Simple.hs1
-rw-r--r--http-conduit.cabal2
5 files changed, 28 insertions, 4 deletions
diff --git a/ChangeLog.md b/ChangeLog.md
index 6993921..dd43e69 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,3 +1,7 @@
+## 2.3.6
+
+* Add `httpSource` to `Network.HTTP.Client.Conduit` [#390](https://github.com/snoyberg/http-client/pull/390).
+
## 2.3.5
* Adds `addToRequestQueryString` helper function
diff --git a/Network/HTTP/Client/Conduit.hs b/Network/HTTP/Client/Conduit.hs
index 48e944a..d50e8be 100644
--- a/Network/HTTP/Client/Conduit.hs
+++ b/Network/HTTP/Client/Conduit.hs
@@ -15,6 +15,7 @@ module Network.HTTP.Client.Conduit
, responseOpen
, responseClose
, acquireResponse
+ , httpSource
-- * Manager helpers
, defaultManagerSettings
, newManager
@@ -31,13 +32,14 @@ module Network.HTTP.Client.Conduit
import Control.Monad (unless)
import Control.Monad.IO.Unlift (MonadIO, liftIO, MonadUnliftIO, withRunInIO)
-import Control.Monad.Reader (MonadReader (..))
+import Control.Monad.Reader (MonadReader (..), runReaderT)
+import Control.Monad.Trans.Resource (MonadResource)
import Data.Acquire (Acquire, mkAcquire, with)
import Data.ByteString (ByteString)
import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L
-import Data.Conduit (ConduitM, ($$+),
- await, yield, ($$++))
+import Data.Conduit (ConduitM, ($$+), ($$++),
+ await, yield, bracketP)
import Data.Int (Int64)
import Data.IORef (newIORef, readIORef, writeIORef)
import Network.HTTP.Client hiding (closeManager,
@@ -172,3 +174,19 @@ httpNoBody req = do
env <- ask
let man = getHttpManager env
liftIO $ H.httpNoBody req man
+
+-- | Same as 'Network.HTTP.Simple.httpSource', but uses 'Manager'
+-- from Reader environment instead of the global one.
+--
+-- Since 2.3.6
+httpSource
+ :: (MonadResource m, MonadIO n, MonadReader env m, HasHttpManager env)
+ => Request
+ -> (Response (ConduitM () ByteString n ()) -> ConduitM () r m ())
+ -> ConduitM () r m ()
+httpSource request withRes = do
+ env <- ask
+ bracketP
+ (runReaderT (responseOpen request) env)
+ responseClose
+ withRes
diff --git a/Network/HTTP/Conduit.hs b/Network/HTTP/Conduit.hs
index 76c592b..e58b50e 100644
--- a/Network/HTTP/Conduit.hs
+++ b/Network/HTTP/Conduit.hs
@@ -158,6 +158,7 @@ module Network.HTTP.Conduit
, rawBody
, decompress
, redirectCount
+ , shouldStripHeaderOnRedirect
, checkResponse
, responseTimeout
, cookieJar
diff --git a/Network/HTTP/Simple.hs b/Network/HTTP/Simple.hs
index 0690d75..9036f88 100644
--- a/Network/HTTP/Simple.hs
+++ b/Network/HTTP/Simple.hs
@@ -95,6 +95,7 @@ import qualified Data.Aeson.Types as A
import qualified Data.Aeson as A
import qualified Data.Traversable as T
import Control.Exception (throw, throwIO, Exception)
+import Data.Monoid
import Data.Typeable (Typeable)
import qualified Data.Conduit as C
import Data.Conduit (runConduit, (.|), ConduitM)
diff --git a/http-conduit.cabal b/http-conduit.cabal
index c3d6249..5c57c33 100644
--- a/http-conduit.cabal
+++ b/http-conduit.cabal
@@ -1,5 +1,5 @@
name: http-conduit
-version: 2.3.5
+version: 2.3.6
license: BSD3
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>