packages feed

http-client-openssl (empty) → 0.2.0.0

raw patch · 5 files changed

+120/−0 lines, 5 filesdep +HsOpenSSLdep +basedep +hspecsetup-changed

Dependencies added: HsOpenSSL, base, hspec, http-client, http-client-openssl, http-types, network

Files

+ LICENSE view
@@ -0,0 +1,20 @@+The 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.
+ Network/HTTP/Client/OpenSSL.hs view
@@ -0,0 +1,48 @@+{-# LANGUAGE ScopedTypeVariables #-}+-- | Support for making connections via the OpenSSL library.+module Network.HTTP.Client.OpenSSL+    ( opensslManagerSettings+    -- , defaultMakeContext+    , withOpenSSL+    ) where++import Network.HTTP.Client+import Network.HTTP.Client.Internal+import Control.Exception+import Network.Socket (HostAddress)+import OpenSSL+import qualified Network.Socket as N+import qualified OpenSSL.Session       as SSL++-- | FIXME This needs better defaults+defaultMakeContext :: IO SSL.SSLContext+defaultMakeContext = SSL.context++-- | Note that it is the caller's responsibility to pass in an appropriate+-- context. Future versions of http-client-openssl will hopefully include a+-- sane, safe default.+opensslManagerSettings :: IO SSL.SSLContext -> ManagerSettings+opensslManagerSettings mkContext = defaultManagerSettings+    { managerTlsConnection = do+        ctx <- mkContext+        return $ \_ha host port -> do+            -- Copied/modified from openssl-streams+            let hints      = N.defaultHints+                                { N.addrFlags = [N.AI_ADDRCONFIG, N.AI_NUMERICSERV]+                                }+            (addrInfo:_) <- N.getAddrInfo (Just hints) (Just host) (Just $ show port)++            let family     = N.addrFamily addrInfo+            let socketType = N.addrSocketType addrInfo+            let protocol   = N.addrProtocol addrInfo+            let address    = N.addrAddress addrInfo++            sock <- N.socket family socketType protocol+            N.connect sock address+            ssl <- SSL.connection ctx sock+            SSL.connect ssl+            makeConnection+                (SSL.read ssl 32752)+                (SSL.write ssl)+                (N.sClose sock)+    }
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ http-client-openssl.cabal view
@@ -0,0 +1,34 @@+name:                http-client-openssl+version:             0.2.0.0+synopsis:            http-client backend using the OpenSSL library.+description:         Intended for use by higher-level libraries.+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.OpenSSL+  other-extensions:    ScopedTypeVariables+  build-depends:       base >= 4 && < 5+                     , http-client >= 0.2+                     , network+                     , HsOpenSSL+  default-language:    Haskell2010++test-suite spec+  main-is:             Spec.hs+  type:                exitcode-stdio-1.0+  hs-source-dirs:      test+  default-language:    Haskell2010+  ghc-options:         -threaded+  build-depends:       base+                     , hspec+                     , http-client+                     , http-client-openssl+                     , http-types+                     , HsOpenSSL
+ test/Spec.hs view
@@ -0,0 +1,16 @@+{-# LANGUAGE OverloadedStrings #-}+import Test.Hspec+import Network.HTTP.Client+import Network.HTTP.Client.OpenSSL+import Network.HTTP.Client.Internal+import Network.HTTP.Types+import qualified OpenSSL.Session       as SSL++main :: IO ()+main = withOpenSSL $ hspec $ do+    it "make a TLS connection" $ do+        manager <- newManager $ opensslManagerSettings SSL.context+        withResponse "https://httpbin.org/status/418"+            { checkStatus = \_ _ _ -> Nothing+            } manager $ \res -> do+            responseStatus res `shouldBe` status418