Skip to content
Merged
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: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ concurrency:
on:
push:
branches:
- master
- main
- ci
pull_request:
branches:
- master
- main
schedule:
- cron: 0 0 * * *

Expand Down
51 changes: 27 additions & 24 deletions http-client-tls/Network/HTTP/Client/TLS.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveDataTypeable #-}
Expand Down Expand Up @@ -27,8 +28,8 @@ import Control.Applicative ((<|>))
import Control.Arrow (first)
import System.Environment (getEnvironment)
import Data.Default
import Network.HTTP.Client hiding (host, port)
import Network.HTTP.Client.Internal hiding (host, port)
import Network.HTTP.Client hiding (withConnection, host, port)
import Network.HTTP.Client.Internal hiding (withConnection, host, port)
import Control.Exception
import qualified Network.Connection as NC
import Network.Socket (HostAddress)
Expand All @@ -44,7 +45,7 @@ import Network.HTTP.Types (status401)
import qualified Crypto.Hash.MD5 as MD5
import Control.Arrow ((***))
import Data.Base16.Types (extractBase16)
import Data.ByteString.Base16 (encodeBase16')
import "base16" Data.ByteString.Base16 (encodeBase16')
import Data.Typeable (Typeable)
import Control.Monad.Catch (MonadThrow, throwM)
import qualified Data.Map as Map
Expand Down Expand Up @@ -124,15 +125,15 @@ 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
}
withConnection context params
convertConnection

getTlsProxyConnection
:: Maybe NC.ConnectionContext
Expand All @@ -141,18 +142,17 @@ 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
}
withConnection context params $ \conn -> do
NC.connectionPut conn connstr
conn' <- convertConnection conn

Expand All @@ -162,6 +162,9 @@ getTlsProxyConnection mcontext tls sock = do

return conn'

withConnection :: NC.ConnectionContext -> NC.ConnectionParams -> (NC.Connection -> IO a) -> IO a
withConnection context params = bracketOnError (NC.connectTo context params) NC.connectionClose

convertConnection :: NC.Connection -> IO Connection
convertConnection conn = makeConnection
(NC.connectionGetChunk conn)
Expand Down
Loading