]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/Postprocess.hs
Many changes...
[Lucu.git] / Network / HTTP / Lucu / Postprocess.hs
index 49c95e809be046489bed306c83db6f77eab12baf..a7c2e070843c45b4f357687c81cebb083a9d02e7 100644 (file)
@@ -15,9 +15,6 @@ import Control.Monad
 import Control.Monad.Unicode
 import Data.Ascii (Ascii, CIAscii)
 import qualified Data.Ascii as A
-import qualified Data.ByteString as Strict (ByteString)
-import qualified Data.ByteString.Char8 as C8 hiding (ByteString)
-import Data.IORef
 import Data.Maybe
 import Data.Monoid.Unicode
 import Data.Time
@@ -31,7 +28,6 @@ import Network.HTTP.Lucu.Interaction
 import Network.HTTP.Lucu.Request
 import Network.HTTP.Lucu.Response
 import Prelude.Unicode
-import System.IO.Unsafe
 
 {-
   
@@ -68,8 +64,8 @@ import System.IO.Unsafe
 
 postprocess ∷ Interaction → STM ()
 postprocess !itr
-    = do reqM ← readItr itr itrRequest id
-         res  ← readItr itr itrResponse id
+    = do reqM ← readItr itrRequest  id itr
+         res  ← readItr itrResponse id itr
          let sc = resStatus res
 
          unless (any (\ p → p sc) [isSuccessful, isRedirection, isError])
@@ -85,26 +81,26 @@ postprocess !itr
                           ⊕ printStatusCode sc
                           ⊕ " but no Allow header." )
 
-         when (sc /= NotModified ∧ isRedirection sc ∧ getHeader "Location" res ≡ Nothing)
+         when (sc  NotModified ∧ isRedirection sc ∧ getHeader "Location" res ≡ Nothing)
              $ abortSTM InternalServerError []
              $ Just
              $ A.toText ( "The status code was "
                           ⊕ printStatusCode sc
                           ⊕ " but no Location header." )
 
-         when (reqM /= Nothing) relyOnRequest
+         when (reqM  Nothing) relyOnRequest
 
          -- itrResponse の内容は relyOnRequest によって變へられてゐる可
          -- 能性が高い。
-         do oldRes ← readItr itr itrResponse id
+         do oldRes ← readItr itrResponse id itr
             newRes ← unsafeIOToSTM
                      $ completeUnconditionalHeaders (itrConfig itr) oldRes
-            writeItr itr itrResponse newRes
+            writeItr itrResponse newRes itr
     where
       relyOnRequest ∷ STM ()
       relyOnRequest
-          = do status ← readItr itr itrResponse resStatus
-               req    ← readItr itr itrRequest fromJust
+          = do status ← readItr itrResponse resStatus itr
+               req    ← readItr itrRequest  fromJust  itr
 
                let reqVer      = reqVersion req
                    canHaveBody = if reqMethod req ≡ HEAD then
@@ -125,10 +121,10 @@ postprocess !itr
                if canHaveBody then
                    when (reqVer ≡ HttpVersion 1 1)
                        $ do updateRes $ setHeader "Transfer-Encoding" "chunked"
-                            writeItr itr itrWillChunkBody True
+                            writeItr itrWillChunkBody True itr
                else
                    -- body 関連のヘッダを削除。但し HEAD なら Content-* は殘す
-                   when (reqMethod req /= HEAD)
+                   when (reqMethod req  HEAD)
                        $ do updateRes $ deleteHeader "Content-Type"
                             updateRes $ deleteHeader "Etag"
                             updateRes $ deleteHeader "Last-Modified"
@@ -137,9 +133,9 @@ postprocess !itr
                case conn of
                  Nothing    → return ()
                  Just value → when (A.toCIAscii value ≡ "close")
-                                  $ writeItr itr itrWillClose True
+                                  $ writeItr itrWillClose True itr
 
-               willClose ← readItr itr itrWillClose id
+               willClose ← readItr itrWillClose id itr
                when willClose
                    $ updateRes $ setHeader "Connection" "close"
 
@@ -148,11 +144,11 @@ postprocess !itr
 
       readHeader ∷ CIAscii → STM (Maybe Ascii)
       {-# INLINE readHeader #-}
-      readHeader = readItr itr itrResponse ∘ getHeader
+      readHeader k = readItr itrResponse (getHeader k) itr
 
       updateRes ∷ (Response → Response) → STM ()
       {-# INLINE updateRes #-}
-      updateRes = updateItr itr itrResponse
+      updateRes f = updateItr itrResponse f itr
 
 completeUnconditionalHeaders ∷ Config → Response → IO Response
 completeUnconditionalHeaders conf = (compDate =≪) ∘ compServer
@@ -169,4 +165,4 @@ completeUnconditionalHeaders conf = (compDate =≪) ∘ compServer
                 Just _  → return res'
 
 getCurrentDate ∷ IO Ascii
-getCurrentDate = HTTP.format <$> getCurrentTime
+getCurrentDate = HTTP.toAscii <$> getCurrentTime