http-client-tls-0.2.0.0/0000755000000000000000000000000012247525235013077 5ustar0000000000000000http-client-tls-0.2.0.0/Setup.hs0000644000000000000000000000005612247525235014534 0ustar0000000000000000import Distribution.Simple main = defaultMain http-client-tls-0.2.0.0/LICENSE0000644000000000000000000000207212247525235014105 0ustar0000000000000000The MIT License (MIT) Copyright (c) 2013 Michael Snoyman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. http-client-tls-0.2.0.0/http-client-tls.cabal0000644000000000000000000000225212247525235017117 0ustar0000000000000000name: http-client-tls version: 0.2.0.0 synopsis: http-client backend using the connection package and tls library description: Intended for use by higher-level libraries, such as http-conduit. homepage: https://github.com/snoyberg/http-client license: MIT license-file: LICENSE author: Michael Snoyman maintainer: michael@snoyman.com category: Network build-type: Simple cabal-version: >=1.10 library exposed-modules: Network.HTTP.Client.TLS other-extensions: ScopedTypeVariables build-depends: base >= 4 && < 5 , data-default , http-client >= 0.2 , connection >= 0.1.3 , network , tls >=1.1 default-language: Haskell2010 test-suite spec main-is: Spec.hs type: exitcode-stdio-1.0 hs-source-dirs: test default-language: Haskell2010 build-depends: base , hspec , http-client , http-client-tls , http-types http-client-tls-0.2.0.0/Network/0000755000000000000000000000000012247525235014530 5ustar0000000000000000http-client-tls-0.2.0.0/Network/HTTP/0000755000000000000000000000000012247525235015307 5ustar0000000000000000http-client-tls-0.2.0.0/Network/HTTP/Client/0000755000000000000000000000000012247525235016525 5ustar0000000000000000http-client-tls-0.2.0.0/Network/HTTP/Client/TLS.hs0000644000000000000000000000647112247525235017533 0ustar0000000000000000{-# LANGUAGE ScopedTypeVariables #-} -- | Support for making connections via the connection package and, in turn, -- the tls package suite. module Network.HTTP.Client.TLS ( tlsManagerSettings , mkManagerSettings , getTlsConnection ) where import Data.Default import Network.HTTP.Client import Network.HTTP.Client.Internal import Control.Exception import qualified Network.Connection as NC import Network.Socket (HostAddress) import qualified Network.TLS as TLS mkManagerSettings :: NC.TLSSettings -> Maybe NC.SockSettings -> ManagerSettings mkManagerSettings tls sock = defaultManagerSettings { managerTlsConnection = getTlsConnection (Just tls) sock , managerRawConnection = case sock of Nothing -> managerRawConnection defaultManagerSettings Just _ -> getTlsConnection Nothing sock , managerRetryableException = \e -> case () of () | ((fromException e)::(Maybe TLS.TLSError))==Just TLS.Error_EOF -> True | otherwise -> case fromException e of Just (_ :: IOException) -> True _ -> case fromException e of -- Note: Some servers will timeout connections by accepting -- the incoming packets for the new request, but closing -- the connection as soon as we try to read. To make sure -- we open a new connection under these circumstances, we -- check for the NoResponseDataReceived exception. Just NoResponseDataReceived -> True _ -> False , managerWrapIOException = let wrapper se = case fromException se of Just e -> toException $ InternalIOException e Nothing -> case fromException se of Just TLS.Terminated{} -> toException $ TlsException se Nothing -> case fromException se of Just TLS.HandshakeFailed{} -> toException $ TlsException se Nothing -> case fromException se of Just TLS.ConnectionNotEstablished -> toException $ TlsException se Nothing -> se in handle $ throwIO . wrapper } tlsManagerSettings :: ManagerSettings tlsManagerSettings = mkManagerSettings def Nothing getTlsConnection :: Maybe NC.TLSSettings -> Maybe NC.SockSettings -> IO (Maybe HostAddress -> String -> Int -> IO Connection) getTlsConnection tls sock = do context <- NC.initConnectionContext return $ \_ha host port -> do conn <- NC.connectTo context NC.ConnectionParams { NC.connectionHostname = host , NC.connectionPort = fromIntegral port , NC.connectionUseSecure = tls , NC.connectionUseSocks = sock } convertConnection conn where convertConnection conn = makeConnection (NC.connectionGetChunk conn) (NC.connectionPut conn) (NC.connectionClose conn) http-client-tls-0.2.0.0/test/0000755000000000000000000000000012247525235014056 5ustar0000000000000000http-client-tls-0.2.0.0/test/Spec.hs0000644000000000000000000000073612247525235015312 0ustar0000000000000000{-# LANGUAGE OverloadedStrings #-} import Test.Hspec import Network.HTTP.Client import Network.HTTP.Client.TLS import Network.HTTP.Client.Internal import Network.HTTP.Types main :: IO () main = hspec $ do it "make a TLS connection" $ do manager <- newManager tlsManagerSettings withResponse "https://httpbin.org/status/418" { checkStatus = \_ _ _ -> Nothing } manager $ \res -> do responseStatus res `shouldBe` status418