Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add low level createConnection/disposeConnection as an alternative to withConnection #527

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions http-client/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
18 changes: 18 additions & 0 deletions http-client/Network/HTTP/Client/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ module Network.HTTP.Client.Core
, httpRedirect
, httpRedirect'
, withConnection
, createConnection
, disposeConnection
, handleClosedRead
) where

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion http-client/http-client.cabal
Original file line number Diff line number Diff line change
@@ -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: <http://www.stackage.org/package/http-client>.
homepage: https://github.com/snoyberg/http-client
Expand Down
Loading