6 -- |Type class for things behaves like a 'I.Handle'.
7 module Network.HTTP.Lucu.HandleLike
12 import Blaze.ByteString.Builder (Builder)
13 import qualified Blaze.ByteString.Builder as BB
14 import qualified Data.ByteString as B
15 import qualified Data.ByteString.Lazy.Char8 as L
17 import qualified OpenSSL.Session as SSL
20 import Prelude.Unicode
21 import qualified System.IO as I
23 class HandleLike h where
24 hGetLBS ∷ h → IO L.ByteString
26 hGetBS ∷ h → Int → IO B.ByteString
27 hPutBS ∷ h → B.ByteString → IO ()
30 hGetPeerCert ∷ h → IO (Maybe X509)
31 hGetPeerCert = const $ return Nothing
39 instance HandleLike I.Handle where
40 hGetLBS = L.hGetContents
49 instance HandleLike SSL.SSL where
50 hGetLBS = SSL.lazyRead
56 = do isValid <- SSL.getVerifyResult s
58 SSL.getPeerCertificate s
63 hFlush _ = return () -- No need to do anything.
64 hClose s = SSL.shutdown s SSL.Bidirectional
67 hPutBuilder ∷ HandleLike h ⇒ h → Builder → IO ()
68 {-# INLINE hPutBuilder #-}
69 hPutBuilder = BB.toByteStringIO ∘ hPutBS