1 module Network.HTTP.Lucu.HandleLike
6 import qualified Data.ByteString as B
7 import qualified Data.ByteString.Lazy.Char8 as L
8 import qualified OpenSSL.Session as SSL
10 import qualified System.IO as I
13 class HandleLike h where
14 hGetLBS :: h -> IO L.ByteString
15 hPutLBS :: h -> L.ByteString -> IO ()
17 hGetBS :: h -> Int -> IO B.ByteString
18 hPutBS :: h -> B.ByteString -> IO ()
20 hPutChar :: h -> Char -> IO ()
22 hPutStr :: h -> String -> IO ()
23 hPutStrLn :: h -> String -> IO ()
25 hGetPeerCert :: h -> IO (Maybe X509)
26 hGetPeerCert = const $ return Nothing
32 instance HandleLike I.Handle where
33 hGetLBS = L.hGetContents
42 hPutStrLn = I.hPutStrLn
48 instance HandleLike SSL.SSL where
49 hGetLBS = SSL.lazyRead
50 hPutLBS = SSL.lazyWrite
55 hPutChar s = hPutLBS s . L.singleton
57 hPutStr s = hPutLBS s . L.pack
58 hPutStrLn s = hPutLBS s . L.pack . (++ "\n")
61 = do isValid <- SSL.getVerifyResult s
63 SSL.getPeerCertificate s
67 hFlush _ = return () -- unneeded
68 hClose s = SSL.shutdown s SSL.Bidirectional