]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/HandleLike.hs
Still working on Router arrow
[Lucu.git] / Network / HTTP / Lucu / HandleLike.hs
index c4a4c62fc23298558b6ee48a0cc906f8191232f4..65d99f40c60aa42f4be092527914e5f6d8d64bed 100644 (file)
@@ -1,7 +1,9 @@
 {-# LANGUAGE
-    DoAndIfThenElse
+    CPP
+  , DoAndIfThenElse
   , UnicodeSyntax
   #-}
+-- |Type class for things behaves like a 'I.Handle'.
 module Network.HTTP.Lucu.HandleLike
     ( HandleLike(..)
     , hPutBuilder
@@ -11,8 +13,10 @@ import Blaze.ByteString.Builder (Builder)
 import qualified Blaze.ByteString.Builder as BB
 import qualified Data.ByteString as B
 import qualified Data.ByteString.Lazy.Char8 as L
+#if defined(HAVE_SSL)
 import qualified OpenSSL.Session as SSL
 import OpenSSL.X509
+#endif
 import Prelude.Unicode
 import qualified System.IO as I
 
@@ -22,8 +26,12 @@ class HandleLike h where
     hGetBS  ∷ h → Int → IO B.ByteString
     hPutBS  ∷ h → B.ByteString → IO ()
 
+#if defined(HAVE_SSL)
     hGetPeerCert ∷ h → IO (Maybe X509)
     hGetPeerCert = const $ return Nothing
+#endif
+    hIsSSL ∷ h → Bool
+    hIsSSL _ = False
 
     hFlush  ∷ h → IO ()
     hClose  ∷ h → IO ()
@@ -37,6 +45,7 @@ instance HandleLike I.Handle where
     hFlush  = I.hFlush
     hClose  = I.hClose
 
+#if defined(HAVE_SSL)
 instance HandleLike SSL.SSL where
     hGetLBS = SSL.lazyRead
 
@@ -49,9 +58,11 @@ instance HandleLike SSL.SSL where
                  SSL.getPeerCertificate s
              else
                  return Nothing
+    hIsSSL _ = True
 
     hFlush _ = return () -- No need to do anything.
     hClose s = SSL.shutdown s SSL.Bidirectional
+#endif
 
 hPutBuilder ∷ HandleLike h ⇒ h → Builder → IO ()
 {-# INLINE hPutBuilder #-}