4 module Network.HTTP.Lucu.HandleLike
9 import Blaze.ByteString.Builder (Builder)
10 import qualified Blaze.ByteString.Builder as BB
11 import qualified Data.ByteString as B
12 import qualified Data.ByteString.Lazy.Char8 as L
13 import qualified OpenSSL.Session as SSL
15 import Prelude.Unicode
16 import qualified System.IO as I
18 class HandleLike h where
19 hGetLBS ∷ h → IO L.ByteString
20 hPutLBS ∷ h → L.ByteString → IO ()
22 hGetBS ∷ h → Int → IO B.ByteString
23 hPutBS ∷ h → B.ByteString → IO ()
25 hGetPeerCert ∷ h → IO (Maybe X509)
26 hGetPeerCert = const $ return Nothing
32 instance HandleLike I.Handle where
33 hGetLBS = L.hGetContents
43 instance HandleLike SSL.SSL where
44 hGetLBS = SSL.lazyRead
45 hPutLBS = SSL.lazyWrite
51 = do isValid <- SSL.getVerifyResult s
53 SSL.getPeerCertificate s
57 hFlush _ = return () -- No need to do anything.
58 hClose s = SSL.shutdown s SSL.Bidirectional
60 hPutBuilder ∷ HandleLike h ⇒ h → Builder → IO ()
61 {-# INLINE hPutBuilder #-}
62 hPutBuilder = BB.toByteStringIO ∘ hPutBS