http-conduit 1.8.2.1 → 1.8.3
raw patch · 3 files changed
+26/−7 lines, 3 files
Files
- Network/HTTP/Conduit.hs +6/−3
- Network/HTTP/Conduit/Manager.hs +17/−3
- http-conduit.cabal +3/−1
Network/HTTP/Conduit.hs view
@@ -100,6 +100,7 @@ , newManager , closeManager , withManager+ , withManagerSettings -- ** Settings , ManagerSettings , managerConnCount@@ -277,13 +278,15 @@ -- This function will 'throwIO' an 'HttpException' for any -- response with a non-2xx status code (besides 3xx redirects up -- to a limit of 10 redirects). It uses 'parseUrl' to parse the--- input. This function essentially wraps 'httpLbsRedirect'.+-- input. This function essentially wraps 'httpLbs'. -- -- Note: Even though this function returns a lazy bytestring, it -- does /not/ utilize lazy I/O, and therefore the entire response -- body will live in memory. If you want constant memory usage,--- you'll need to use the @conduit@ package and 'http' or--- 'httpRedirect' directly.+-- you'll need to use the @conduit@ package and 'http' directly.+--+-- Note: This function creates a new 'Manager'. It should be avoided+-- in production code. simpleHttp :: MonadIO m => String -> m L.ByteString simpleHttp url = liftIO $ withManager $ \man -> do url' <- liftIO $ parseUrl url
Network/HTTP/Conduit/Manager.hs view
@@ -12,6 +12,7 @@ , getConn , ConnReuse (..) , withManager+ , withManagerSettings , ConnRelease , ManagedConn (..) , defaultCheckCerts@@ -90,8 +91,8 @@ CertificateUsageAccept -> certificateVerifyChain certStore certs rejected -> return rejected --- | Keeps track of open connections for keep-alive. May be used--- concurrently by multiple threads.+-- | Keeps track of open connections for keep-alive.+-- If possible, you should share a single 'Manager' between multiple threads and requests. data Manager = Manager { mConns :: !(I.IORef (Maybe (Map.Map ConnKey (NonEmptyList ConnInfo)))) -- ^ @Nothing@ indicates that the manager is closed.@@ -148,6 +149,9 @@ | otherwise = (l, Just x) -- | Create a 'Manager'. You must manually call 'closeManager' to shut it down.+--+-- Creating a new 'Manager' is an expensive operation, you are advised to share+-- a single 'Manager' between requests instead. newManager :: ManagerSettings -> IO Manager newManager ms = do icertStore <- I.newIORef Nothing@@ -254,7 +258,7 @@ -- | Create a new manager, use it in the provided function, and then release it. -- -- This function uses the default manager settings. For more control, use--- 'newManager'.+-- 'withManagerSettings'. withManager :: ( MonadIO m , MonadBaseControl IO m , MonadThrow m@@ -262,6 +266,16 @@ ) => (Manager -> ResourceT m a) -> m a withManager f = runResourceT $ do (_, manager) <- allocate (newManager def) closeManager+ f manager++-- | Create a new manager with provided settings, use it in the provided function, and then release it.+withManagerSettings :: ( MonadIO m+ , MonadBaseControl IO m+ , MonadThrow m+ , MonadUnsafeIO m+ ) => ManagerSettings -> (Manager -> ResourceT m a) -> m a+withManagerSettings s f = runResourceT $ do+ (_, manager) <- allocate (newManager s) closeManager f manager -- | Close all connections in a 'Manager'. Afterwards, the
http-conduit.cabal view
@@ -1,5 +1,5 @@ name: http-conduit-version: 1.8.2.1+version: 1.8.3 license: BSD3 license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>@@ -7,6 +7,8 @@ synopsis: HTTP client package with conduit interface and HTTPS support. description: This package uses attoparsec for parsing the actual contents of the HTTP connection. It also provides higher-level functions which allow you to avoid direct usage of conduits. See <http://www.yesodweb.com/book/http-conduit> for more information.+ .+ "Network.HTTP.Conduit.Browser" module has been moved to <http://hackage.haskell.org/package/http-conduit-browser/> category: Web, Conduit stability: Stable cabal-version: >= 1.8