Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e4d0b9f

Browse files
authored
Merge pull request haskell-github#419 from robbiemcmichael/samples-openssl-flag
Add openssl flag to samples
2 parents e99858d + 75afbf8 commit e4d0b9f

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

cabal.project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ constraints: hashable ^>=1.3
88
constraints: semigroups ^>=0.19
99

1010
constraints: github +openssl
11+
constraints: github-samples +openssl

samples/Operational/Operational.hs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE DataKinds #-}
23
{-# LANGUAGE GADTs #-}
34
{-# LANGUAGE OverloadedStrings #-}
@@ -9,11 +10,17 @@ import Prelude ()
910
import Control.Monad.Operational
1011
import Control.Monad.Trans.Except (ExceptT (..), runExceptT)
1112
import Network.HTTP.Client (Manager, newManager, ManagerSettings)
13+
14+
#ifdef MIN_VERSION_http_client_tls
15+
import Network.HTTP.Client.TLS (tlsManagerSettings)
16+
#else
1217
import Network.HTTP.Client.OpenSSL (opensslManagerSettings, withOpenSSL)
1318

14-
import qualified GitHub as GH
1519
import qualified OpenSSL.Session as SSL
1620
import qualified OpenSSL.X509.SystemStore as SSL
21+
#endif
22+
23+
import qualified GitHub as GH
1724

1825
data R a where
1926
R :: FromJSON a => GH.Request 'GH.RA a -> R a
@@ -42,6 +49,10 @@ main = withOpenSSL $ do
4249
githubRequest $ GH.ownerInfoForR (GH.simpleOwnerLogin . GH.repoOwner $ repo)
4350
print owner
4451

52+
#ifdef MIN_VERSION_http_client_tls
53+
withOpenSSL :: IO a -> IO a
54+
withOpenSSL = id
55+
#else
4556
tlsManagerSettings :: ManagerSettings
4657
tlsManagerSettings = opensslManagerSettings $ do
4758
ctx <- SSL.context
@@ -52,3 +63,4 @@ tlsManagerSettings = opensslManagerSettings $ do
5263
SSL.contextLoadSystemCerts ctx
5364
SSL.contextSetVerificationMode ctx $ SSL.VerifyPeer True True Nothing
5465
return ctx
66+
#endif

samples/github-samples.cabal

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ tested-with:
1717
|| ==8.6.5
1818
|| ==8.8.1
1919

20+
flag openssl
21+
description: "Use http-client-openssl"
22+
manual: True
23+
default: False
24+
2025
library
2126
hs-source-dirs: src
2227
ghc-options: -Wall
@@ -38,15 +43,22 @@ executable github-operational
3843
, base-compat-batteries
3944
, github
4045
, github-samples
41-
, HsOpenSSL
42-
, HsOpenSSL-x509-system
4346
, http-client
44-
, http-client-openssl
4547
, operational
4648
, text
4749
, transformers
4850
, transformers-compat
4951

52+
if flag(openssl)
53+
build-depends:
54+
HsOpenSSL
55+
, HsOpenSSL-x509-system
56+
, http-client-openssl
57+
58+
else
59+
build-depends:
60+
http-client-tls
61+
5062
default-language: Haskell2010
5163

5264
common deps

0 commit comments

Comments
 (0)