@@ -15,16 +15,15 @@ module Network.HTTP.StackClient
1515 , withResponseByManager
1616 ) where
1717
18- import Control.Monad.Catch (MonadMask )
1918import Data.Aeson (FromJSON )
2019import qualified Data.ByteString as Strict
2120import Data.ByteString.Lazy (ByteString )
22- import Data.Conduit (ConduitM , Sink )
21+ import Data.Conduit (ConduitM , Sink , transPipe )
2322import qualified Network.HTTP.Client
2423import Network.HTTP.Client (BodyReader , Manager , Request , Response )
2524import Network.HTTP.Simple (setRequestHeader )
2625import qualified Network.HTTP.Simple
27- import UnliftIO (MonadIO )
26+ import UnliftIO (MonadIO , MonadUnliftIO , withRunInIO , withUnliftIO , unliftIO )
2827
2928
3029setUserAgent :: Request -> Request
@@ -47,15 +46,18 @@ httpNoBody :: MonadIO m => Request -> m (Response ())
4746httpNoBody = Network.HTTP.Simple. httpNoBody . setUserAgent
4847
4948
50- httpSink :: (MonadIO m , MonadMask m ) => Request -> (Response () -> Sink Strict. ByteString m a ) -> m a
51- httpSink = Network.HTTP.Simple. httpSink . setUserAgent
49+ httpSink :: MonadUnliftIO m => Request -> (Response () -> Sink Strict. ByteString m a ) -> m a
50+ httpSink req inner = withUnliftIO $ \ u ->
51+ Network.HTTP.Simple. httpSink (setUserAgent req) (transPipe (unliftIO u) . inner)
5252
5353
5454withResponse
55- :: (MonadIO m , MonadMask m , MonadIO n )
55+ :: (MonadUnliftIO m , MonadIO n )
5656 => Request -> (Response (ConduitM i Strict. ByteString n () ) -> m a ) -> m a
57- withResponse = Network.HTTP.Simple. withResponse . setUserAgent
57+ withResponse req inner = withRunInIO $ \ run ->
58+ Network.HTTP.Simple. withResponse (setUserAgent req) (run . inner)
5859
5960
60- withResponseByManager :: Request -> Manager -> (Response BodyReader -> IO a ) -> IO a
61- withResponseByManager = Network.HTTP.Client. withResponse . setUserAgent
61+ withResponseByManager :: MonadUnliftIO m => Request -> Manager -> (Response BodyReader -> m a ) -> m a
62+ withResponseByManager req man inner = withRunInIO $ \ run ->
63+ Network.HTTP.Client. withResponse (setUserAgent req) man (run . inner)
0 commit comments