Skip to content

Instantly share code, notes, and snippets.

@cstrahan
Forked from superduper/SslClientAuth.hs
Created November 25, 2015 23:29
Show Gist options
  • Select an option

  • Save cstrahan/5ba3b9872707b0be6d6f to your computer and use it in GitHub Desktop.

Select an option

Save cstrahan/5ba3b9872707b0be6d6f to your computer and use it in GitHub Desktop.
Example how to use wreq with ssl
{-# LANGUAGE OverloadedStrings #-}
module Network.HttpSSL (
postSSL
, SSLOptions (..)
) where
{-
build-depends:
wreq
, HsOpenSSL
, http-client-openssl
, lens
-}
import Control.Lens
import Data.ByteString.Lazy (ByteString)
import Network.HTTP.Client.OpenSSL
import Network.Wreq
import OpenSSL (withOpenSSL)
import OpenSSL.Session (SSLContext)
import qualified OpenSSL.Session as SSL
data SSLOptions = SSLOptions {
optionsClientCert :: FilePath
, optionsCaCert :: FilePath }
setupSSLCtx :: SSLOptions -> IO SSLContext
setupSSLCtx (SSLOptions clientCert caCert) =
do ctx <- SSL.context
SSL.contextSetPrivateKeyFile ctx clientCert
SSL.contextSetCertificateFile ctx caCert
return ctx
postSSL :: SSLOptions -- ^ Options
-> String -- ^ URL
-> ByteString
-> IO (Response ByteString)
postSSL sopts url b =
let mkOpts c = defaults & manager .~ Left (opensslManagerSettings c)
call o = postWith (mkOpts o) url
in withOpenSSL $ call (setupSSLCtx sopts) b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment