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
37 instance HandleLike I.Handle where
38 hGetLBS = L.hGetContents
47 instance HandleLike SSL.SSL where
48 hGetLBS = SSL.lazyRead
54 = do isValid <- SSL.getVerifyResult s
56 SSL.getPeerCertificate s
60 hFlush _ = return () -- No need to do anything.
61 hClose s = SSL.shutdown s SSL.Bidirectional
64 hPutBuilder ∷ HandleLike h ⇒ h → Builder → IO ()
65 {-# INLINE hPutBuilder #-}
66 hPutBuilder = BB.toByteStringIO ∘ hPutBS