Skip to content
Closed
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
44 changes: 23 additions & 21 deletions http-client-tls/Network/HTTP/Client/TLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,16 @@ getTlsConnection :: Maybe NC.ConnectionContext
-> IO (Maybe HostAddress -> String -> Int -> IO Connection)
getTlsConnection mcontext tls sock = do
context <- maybe NC.initConnectionContext return mcontext
return $ \_ha host port -> bracketOnError
(NC.connectTo context NC.ConnectionParams
{ NC.connectionHostname = strippedHostName host
, NC.connectionPort = fromIntegral port
, NC.connectionUseSecure = tls
, NC.connectionUseSocks = sock
})
NC.connectionClose
convertConnection
return $ \ha host port -> do
let params = NC.ConnectionParams
{ NC.connectionHostname = strippedHostName host
, NC.connectionPort = fromIntegral port
, NC.connectionUseSecure = tls
, NC.connectionUseSocks = sock
}
withSocket (const $ pure ()) ha host port $ \socket -> do
conn <- NC.connectFromSocket context socket params
convertConnection conn

getTlsProxyConnection
:: Maybe NC.ConnectionContext
Expand All @@ -141,18 +142,19 @@ getTlsProxyConnection
-> IO (S.ByteString -> (Connection -> IO ()) -> String -> Maybe HostAddress -> String -> Int -> IO Connection)
getTlsProxyConnection mcontext tls sock = do
context <- maybe NC.initConnectionContext return mcontext
return $ \connstr checkConn serverName _ha host port -> bracketOnError
(NC.connectTo context NC.ConnectionParams
{ NC.connectionHostname = strippedHostName serverName
, NC.connectionPort = fromIntegral port
, NC.connectionUseSecure = Nothing
, NC.connectionUseSocks =
case sock of
Just _ -> error "Cannot use SOCKS and TLS proxying together"
Nothing -> Just $ NC.OtherProxy (strippedHostName host) $ fromIntegral port
})
NC.connectionClose
$ \conn -> do
return $ \connstr checkConn serverName ha host port -> do
let params = NC.ConnectionParams
{ NC.connectionHostname = strippedHostName serverName
, NC.connectionPort = fromIntegral port
, NC.connectionUseSecure = Nothing
, NC.connectionUseSocks =
case sock of
Just _ -> error "Cannot use SOCKS and TLS proxying together"
Nothing -> Just $ NC.OtherProxy (strippedHostName host)
$ fromIntegral port
}
withSocket (const $ pure ()) ha host port $ \socket -> do
conn <- NC.connectFromSocket context socket params
NC.connectionPut conn connstr
conn' <- convertConnection conn

Expand Down