From 6f67e5e883f33274ac69249d97567b0d98eaf5fe Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Tue, 1 Feb 2022 12:27:53 -0800 Subject: [PATCH] Add low level createConnection/disposeConnection --- http-client/ChangeLog.md | 4 ++++ http-client/Network/HTTP/Client/Core.hs | 18 ++++++++++++++++++ http-client/http-client.cabal | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/http-client/ChangeLog.md b/http-client/ChangeLog.md index e29dcd5a..d83abe1f 100644 --- a/http-client/ChangeLog.md +++ b/http-client/ChangeLog.md @@ -1,5 +1,9 @@ # Changelog for http-client +## 0.7.17 + +* Expose low-level createConnection/disposeConnection functions. + ## 0.7.16 * Add `responseEarlyHints` field to `Response`, containing a list of all HTTP 103 Early Hints headers received from the server. diff --git a/http-client/Network/HTTP/Client/Core.hs b/http-client/Network/HTTP/Client/Core.hs index 777384f7..f9e7c17a 100644 --- a/http-client/Network/HTTP/Client/Core.hs +++ b/http-client/Network/HTTP/Client/Core.hs @@ -12,6 +12,8 @@ module Network.HTTP.Client.Core , httpRedirect , httpRedirect' , withConnection + , createConnection + , disposeConnection , handleClosedRead ) where @@ -298,3 +300,19 @@ withConnection origReq man action = do mHttpConn <- getConn (mSetProxy man origReq) man action (managedResource mHttpConn) <* keepAlive mHttpConn `finally` managedRelease mHttpConn DontReuse + +-- | Create a @Connection@ acquired from the given @Manager@. +-- +-- You should use this only when you have to read and write interactively +-- through the connection (e.g. connection by the WebSocket protocol), and you need +-- to use a bracket-style combinator and @disposeConnection@ +-- +-- @since 0.7.17 +createConnection :: Request -> Manager -> IO (Managed Connection, Connection, IO ()) +createConnection origReq man = do + mHttpConn <- getConn (mSetProxy man origReq) man + return (mHttpConn, managedResource mHttpConn, keepAlive mHttpConn) + +-- | Dispose of a @Connection@ acquired from @createConnection@. +disposeConnection :: Managed Connection -> IO () +disposeConnection = flip managedRelease DontReuse diff --git a/http-client/http-client.cabal b/http-client/http-client.cabal index f8d4f0d4..85862820 100644 --- a/http-client/http-client.cabal +++ b/http-client/http-client.cabal @@ -1,5 +1,5 @@ name: http-client -version: 0.7.16 +version: 0.7.17 synopsis: An HTTP client engine description: Hackage documentation generation is not reliable. For up to date documentation, please see: . homepage: https://github.com/snoyberg/http-client