Skip to content

Instantly share code, notes, and snippets.

@j-keck
Created October 30, 2015 13:19
Show Gist options
  • Save j-keck/4f025ea39d6da259c1dc to your computer and use it in GitHub Desktop.
Save j-keck/4f025ea39d6da259c1dc to your computer and use it in GitHub Desktop.
haskell wreq: disable certificate validation
name: disable-certifcate-validation
version: 0.1.0.0
synopsis: Simple project template from stack
description: Please see README.md
homepage: http://github.com/j-keck/disable-certifcate-validation#readme
license: BSD3
license-file: LICENSE
author: j-keck
maintainer: jhyphenkeck@gmail.com
copyright: 2010 Author Here
category: Web
build-type: Simple
cabal-version: >=1.10
executable disable-certifcate-validation
hs-source-dirs: src
main-is: Main.hs
default-language: Haskell2010
build-depends: base >= 4.7 && < 5
, bytestring
, connection
, http-client-tls
, lens
, wreq
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Exception (SomeException, try)
import Control.Lens
import qualified Data.ByteString.Lazy as BL
import Network.Connection (TLSSettings (..))
import Network.HTTP.Client.TLS (mkManagerSettings)
import Network.Wreq
urlWithInvalidCert = "https://cacert.org"
main :: IO ()
main = do
res1 <- try (get urlWithInvalidCert) :: IO (Either SomeException (Response BL.ByteString))
-- Left (TlsExceptionHostPort (HandshakeFailed (Error_Protocol ("certificate rejected: [SelfSigned]",True,CertificateUnknown))) "cacert.org" 443)
print res1
res2 <- try (get' urlWithInvalidCert) :: IO (Either SomeException (Response BL.ByteString))
-- Right (Status {statusCode = 200, statusMessage = "OK"})
print $ fmap (^. responseStatus) res2
get' url = let opts = defaults & manager .~ Left (mkManagerSettings (TLSSettingsSimple True False False) Nothing)
in getWith opts url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment