5 module Network.HTTP.Lucu.HandleLike
10 import Blaze.ByteString.Builder (Builder)
11 import qualified Blaze.ByteString.Builder as BB
12 import qualified Data.ByteString as B
13 import qualified Data.ByteString.Lazy.Char8 as L
14 import qualified OpenSSL.Session as SSL
16 import Prelude.Unicode
17 import qualified System.IO as I
19 class HandleLike h where
20 hGetLBS ∷ h → IO L.ByteString
22 hGetBS ∷ h → Int → IO B.ByteString
23 hPutBS ∷ h → B.ByteString → IO ()
25 hGetPeerCert ∷ h → IO (Maybe X509)
26 hGetPeerCert = const $ return Nothing
31 instance HandleLike I.Handle where
32 hGetLBS = L.hGetContents
40 instance HandleLike SSL.SSL where
41 hGetLBS = SSL.lazyRead
47 = do isValid <- SSL.getVerifyResult s
49 SSL.getPeerCertificate s
53 hFlush _ = return () -- No need to do anything.
54 hClose s = SSL.shutdown s SSL.Bidirectional
56 hPutBuilder ∷ HandleLike h ⇒ h → Builder → IO ()
57 {-# INLINE hPutBuilder #-}
58 hPutBuilder = BB.toByteStringIO ∘ hPutBS