]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/Interaction.hs
Fixed many bugs...
[Lucu.git] / Network / HTTP / Lucu / Interaction.hs
index 58215792fd968846532b6e7f27c065c4f874203e..4ac7c093607729fe8784acc3f8e914c96fed1b66 100644 (file)
@@ -9,21 +9,19 @@ module Network.HTTP.Lucu.Interaction
     , InteractionQueue
     , newInteractionQueue
     , newInteraction
-    , defaultPageContentType
 
     , setResponseStatus
     )
     where
 import Blaze.ByteString.Builder (Builder)
 import Control.Concurrent.STM
-import Data.Ascii (Ascii)
 import qualified Data.ByteString as BS
+import Data.Monoid.Unicode
 import Data.Sequence (Seq)
 import qualified Data.Sequence as S
 import Data.Text (Text)
 import Network.Socket
 import Network.HTTP.Lucu.Config
-import Network.HTTP.Lucu.Headers
 import Network.HTTP.Lucu.HttpVersion
 import Network.HTTP.Lucu.Preprocess
 import Network.HTTP.Lucu.Request
@@ -41,7 +39,7 @@ data Interaction = Interaction {
     , itrExpectedContinue  ∷ !(Maybe Bool)
     , itrReqBodyLength     ∷ !(Maybe RequestBodyLength)
 
-    , itrReqBodyWanted     ∷ !(TVar (Maybe Int))
+    , itrReqBodyWanted     ∷ !(TVar Int)
     , itrReqBodyWasteAll   ∷ !(TVar Bool)
     , itrReqChunkIsOver    ∷ !(TVar Bool)
     , itrReceivedBody      ∷ !(TVar (Seq BS.ByteString))
@@ -51,8 +49,8 @@ data Interaction = Interaction {
     , itrWillChunkBody     ∷ !(TVar Bool)
     , itrWillDiscardBody   ∷ !(TVar Bool)
     , itrWillClose         ∷ !(TVar Bool)
+    , itrResponseHasCType  ∷ !(TVar Bool)
     , itrBodyToSend        ∷ !(TMVar Builder)
-    , itrSentNoBodySoFar   ∷ !(TVar Bool)
 
     , itrState             ∷ !(TVar InteractionState)
     }
@@ -71,9 +69,6 @@ type InteractionQueue = TVar (Seq Interaction)
 newInteractionQueue ∷ IO InteractionQueue
 newInteractionQueue = newTVarIO S.empty
 
-defaultPageContentType ∷ Ascii
-defaultPageContentType = "application/xhtml+xml"
-
 newInteraction ∷ Config
                → PortNumber
                → SockAddr
@@ -85,23 +80,23 @@ newInteraction conf@(Config {..}) port addr cert request
              res = Response {
                      resVersion = HttpVersion 1 1
                    , resStatus  = arInitialStatus ar
-                   , resHeaders = singleton "Content-Type" defaultPageContentType
+                   , resHeaders = (∅)
                    }
 
-         reqBodyWanted   ← newTVarIO Nothing -- Resource が要求してゐるチャンク長
-         reqBodyWasteAll ← newTVarIO False   -- 殘りの body を讀み捨てよと云ふ要求
-         reqChunkIsOver  ← newTVarIO False   -- 最後のチャンクを讀み終へた
+         reqBodyWanted   ← newTVarIO 0
+         reqBodyWasteAll ← newTVarIO False
+         reqChunkIsOver  ← newTVarIO False
          receivedBody    ← newTVarIO S.empty
          receivedBodyLen ← newTVarIO 0
 
-         response        ← newTVarIO res
-         willChunkBody   ← newTVarIO False
-         willDiscardBody ← newTVarIO False
-         willClose       ← newTVarIO False
-         bodyToSend      ← newEmptyTMVarIO
-         sentNoBodySoFar ← newTVarIO True
+         response         ← newTVarIO res
+         willChunkBody    ← newTVarIO False
+         willDiscardBody  ← newTVarIO (arWillDiscardBody ar)
+         willClose        ← newTVarIO (arWillClose       ar)
+         bodyToSend       ← newEmptyTMVarIO
+         responseHasCType ← newTVarIO False
 
-         state           ← newTVarIO ExaminingRequest
+         state            ← newTVarIO ExaminingRequest
 
          return Interaction {
                       itrConfig       = conf
@@ -124,8 +119,8 @@ newInteraction conf@(Config {..}) port addr cert request
                     , itrWillChunkBody    = willChunkBody
                     , itrWillDiscardBody  = willDiscardBody
                     , itrWillClose        = willClose
+                    , itrResponseHasCType = responseHasCType
                     , itrBodyToSend       = bodyToSend
-                    , itrSentNoBodySoFar  = sentNoBodySoFar
                     
                     , itrState            = state
                     }