@@ -22,15 +22,16 @@ barely tested. The current implementation doesn't verify server's identity.
2222It only allows you to connect to a mongodb server using TLS protocol.
2323-}
2424module Database.MongoDB.Transport.Tls
25- (connect)
25+ ( connect
26+ , connectWithTlsParams
27+ )
2628where
2729
2830import Data.IORef
29- import Data.Monoid
31+
3032import qualified Data.ByteString as ByteString
3133import qualified Data.ByteString.Lazy as Lazy.ByteString
3234import Data.Default.Class (def )
33- import Control.Applicative ((<$>) )
3435import Control.Exception (bracketOnError )
3536import Control.Monad (when , unless )
3637import System.IO
@@ -45,15 +46,19 @@ import Database.MongoDB.Query (access, slaveOk, retrieveServerData)
4546
4647-- | Connect to mongodb using TLS
4748connect :: HostName -> PortID -> IO Pipe
48- connect host port = bracketOnError (connectTo host port) hClose $ \ handle -> do
49-
50- let params = (TLS. defaultParamsClient host " " )
49+ connect host port = connectWithTlsParams params host port
50+ where
51+ params = (TLS. defaultParamsClient host " " )
5152 { TLS. clientSupported = def
52- { TLS. supportedCiphers = TLS. ciphersuite_default}
53+ { TLS. supportedCiphers = TLS. ciphersuite_default }
5354 , TLS. clientHooks = def
54- { TLS. onServerCertificate = \ _ _ _ _ -> return [] }
55+ { TLS. onServerCertificate = \ _ _ _ _ -> return [] }
5556 }
56- context <- TLS. contextNew handle params
57+
58+ -- | Connect to mongodb using TLS using provided TLS client parameters
59+ connectWithTlsParams :: TLS. ClientParams -> HostName -> PortID -> IO Pipe
60+ connectWithTlsParams clientParams host port = bracketOnError (connectTo host port) hClose $ \ handle -> do
61+ context <- TLS. contextNew handle clientParams
5762 TLS. handshake context
5863
5964 conn <- tlsConnection context
0 commit comments