diff options
author | MichaelSnoyman <> | 2020-11-17 15:07:00 (GMT) |
---|---|---|
committer | hdiff <hdiff@hdiff.luite.com> | 2020-11-17 15:07:00 (GMT) |
commit | 120c857aee1ec3d869483bde9789659070329cbd (patch) | |
tree | 7f69eaac060663ec4172029216d6f7d0e3617852 | |
parent | 379da5552c6a5de0f47cbb98298324bf6083bc2a (diff) |
version 0.7.30.7.3
-rw-r--r-- | ChangeLog.md | 4 | ||||
-rw-r--r-- | Network/HTTP/Client/Connection.hs | 35 | ||||
-rw-r--r-- | http-client.cabal | 2 |
3 files changed, 29 insertions, 12 deletions
diff --git a/ChangeLog.md b/ChangeLog.md index 634a90d..78fb0b8 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,9 @@ # Changelog for http-client +## 0.7.3 + +* Added `withSocket` to `Network.HTTP.Client.Connection`. + ## 0.7.2.1 * Fix bug in `useProxySecureWithoutConnect`. diff --git a/Network/HTTP/Client/Connection.hs b/Network/HTTP/Client/Connection.hs index e56a8cf..0e329cd 100644 --- a/Network/HTTP/Client/Connection.hs +++ b/Network/HTTP/Client/Connection.hs @@ -10,6 +10,7 @@ module Network.HTTP.Client.Connection , openSocketConnectionSize , makeConnection , socketConnection + , withSocket ) where import Data.ByteString (ByteString, empty) @@ -144,7 +145,17 @@ openSocketConnectionSize :: (Socket -> IO ()) -> String -- ^ host -> Int -- ^ port -> IO Connection -openSocketConnectionSize tweakSocket chunksize hostAddress' host' port' = do +openSocketConnectionSize tweakSocket chunksize hostAddress' host' port' = + withSocket tweakSocket hostAddress' host' port' $ \ sock -> + socketConnection sock chunksize + +withSocket :: (Socket -> IO ()) + -> Maybe HostAddress + -> String -- ^ host + -> Int -- ^ port + -> (Socket -> IO a) + -> IO a +withSocket tweakSocket hostAddress' host' port' f = do let hints = NS.defaultHints { NS.addrSocketType = NS.Stream } addrs <- case hostAddress' of Nothing -> @@ -160,16 +171,18 @@ openSocketConnectionSize tweakSocket chunksize hostAddress' host' port' = do , NS.addrCanonName = Nothing }] - firstSuccessful addrs $ \addr -> - E.bracketOnError - (NS.socket (NS.addrFamily addr) (NS.addrSocketType addr) - (NS.addrProtocol addr)) - NS.close - (\sock -> do - NS.setSocketOption sock NS.NoDelay 1 - tweakSocket sock - NS.connect sock (NS.addrAddress addr) - socketConnection sock chunksize) + E.bracketOnError (firstSuccessful addrs $ openSocket tweakSocket) NS.close f + +openSocket tweakSocket addr = + E.bracketOnError + (NS.socket (NS.addrFamily addr) (NS.addrSocketType addr) + (NS.addrProtocol addr)) + NS.close + (\sock -> do + NS.setSocketOption sock NS.NoDelay 1 + tweakSocket sock + NS.connect sock (NS.addrAddress addr) + return sock) firstSuccessful :: [NS.AddrInfo] -> (NS.AddrInfo -> IO a) -> IO a firstSuccessful [] _ = error "getAddrInfo returned empty list" diff --git a/http-client.cabal b/http-client.cabal index 7e0f589..0b8cf36 100644 --- a/http-client.cabal +++ b/http-client.cabal @@ -1,5 +1,5 @@ name: http-client -version: 0.7.2.1 +version: 0.7.3 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 |