]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/Interaction.hs
Added a configuration flag -fssl to enable SSL support. (default: off)
[Lucu.git] / Network / HTTP / Lucu / Interaction.hs
index 3be8928bf83a7edf473458c6760b06275b3cf886..018ee00d0eaa65e197c508a8d8d7c968d2fb3fe2 100644 (file)
@@ -1,5 +1,6 @@
 {-# LANGUAGE
-    DeriveDataTypeable
+    CPP
+  , DeriveDataTypeable
   , ExistentialQuantification
   , OverloadedStrings
   , RecordWildCards
@@ -44,7 +45,9 @@ import Network.HTTP.Lucu.Headers
 import Network.HTTP.Lucu.Preprocess
 import Network.HTTP.Lucu.Request
 import Network.HTTP.Lucu.Response
+#if defined(HAVE_SSL)
 import OpenSSL.X509
+#endif
 
 class Typeable i ⇒ Interaction i where
     toInteraction ∷ i → SomeInteraction
@@ -109,7 +112,6 @@ mkSemanticallyInvalidInteraction ∷ Config
                                  → IO SemanticallyInvalidInteraction
 mkSemanticallyInvalidInteraction config@(Config {..}) (AugmentedRequest {..})
     = do date ← getCurrentDate
-         -- FIXME: DRY
          let res  = setHeader "Server"       cnfServerSoftware      $
                     setHeader "Date"         date                   $
                     setHeader "Content-Type" defaultPageContentType $
@@ -133,7 +135,9 @@ data NormalInteraction
     = NI {
         niConfig           ∷ !Config
       , niRemoteAddr       ∷ !SockAddr
+#if defined(HAVE_SSL)
       , niRemoteCert       ∷ !(Maybe X509)
+#endif
       , niRequest          ∷ !Request
       , niResourcePath     ∷ ![Strict.ByteString]
       , niExpectedContinue ∷ !Bool
@@ -148,6 +152,7 @@ data NormalInteraction
       , niWillDiscardBody  ∷ !(TVar Bool)
       , niWillClose        ∷ !(TVar Bool)
       , niResponseHasCType ∷ !(TVar Bool)
+      -- FIXME: use TBChan Builder (in stm-chans package)
       , niBodyToSend       ∷ !(TMVar Builder)
 
       , niState            ∷ !(TVar InteractionState)
@@ -172,11 +177,17 @@ data InteractionState
 
 mkNormalInteraction ∷ Config
                     → SockAddr
+#if defined(HAVE_SSL)
                     → Maybe X509
+#endif
                     → AugmentedRequest
                     → [Strict.ByteString]
                     → IO NormalInteraction
+#if defined(HAVE_SSL)
 mkNormalInteraction config remoteAddr remoteCert (AugmentedRequest {..}) rsrcPath
+#else
+mkNormalInteraction config remoteAddr (AugmentedRequest {..}) rsrcPath
+#endif
     = do receiveBodyReq   ← newEmptyTMVarIO
          receivedBody     ← newEmptyTMVarIO
 
@@ -192,7 +203,9 @@ mkNormalInteraction config remoteAddr remoteCert (AugmentedRequest {..}) rsrcPat
          return NI {
                   niConfig           = config
                 , niRemoteAddr       = remoteAddr
+#if defined(HAVE_SSL)
                 , niRemoteCert       = remoteCert
+#endif
                 , niRequest          = arRequest
                 , niResourcePath     = rsrcPath
                 , niExpectedContinue = arExpectedContinue
@@ -217,11 +230,12 @@ type InteractionQueue = TVar (Seq SomeInteraction)
 mkInteractionQueue ∷ IO InteractionQueue
 mkInteractionQueue = newTVarIO (∅)
 
-setResponseStatus ∷ NormalInteraction → StatusCode → STM ()
+-- FIXME: Response.hs should provide setStatus ∷ sc → Response → Response
+setResponseStatus ∷ StatusCode sc ⇒ NormalInteraction → sc → STM ()
 setResponseStatus (NI {..}) sc
     = do res ← readTVar niResponse
          let res' = res {
-                      resStatus = sc
+                      resStatus = fromStatusCode sc
                     }
          writeTVar niResponse res'