5 -- |Type class for things behaves like a 'I.Handle'.
6 module Network.HTTP.Lucu.HandleLike
11 import Blaze.ByteString.Builder (Builder)
12 import qualified Blaze.ByteString.Builder as BB
13 import qualified Data.ByteString as B
14 import qualified Data.ByteString.Lazy.Char8 as L
15 import qualified OpenSSL.Session as SSL
17 import Prelude.Unicode
18 import qualified System.IO as I
20 class HandleLike h where
21 hGetLBS ∷ h → IO L.ByteString
23 hGetBS ∷ h → Int → IO B.ByteString
24 hPutBS ∷ h → B.ByteString → IO ()
26 hGetPeerCert ∷ h → IO (Maybe X509)
27 hGetPeerCert = const $ return Nothing
32 instance HandleLike I.Handle where
33 hGetLBS = L.hGetContents
41 instance HandleLike SSL.SSL where
42 hGetLBS = SSL.lazyRead
48 = do isValid <- SSL.getVerifyResult s
50 SSL.getPeerCertificate s
54 hFlush _ = return () -- No need to do anything.
55 hClose s = SSL.shutdown s SSL.Bidirectional
57 hPutBuilder ∷ HandleLike h ⇒ h → Builder → IO ()
58 {-# INLINE hPutBuilder #-}
59 hPutBuilder = BB.toByteStringIO ∘ hPutBS