]> gitweb @ CieloNegro.org - Lucu.git/commitdiff
Still working on Postprocess...
authorPHO <pho@cielonegro.org>
Thu, 25 Aug 2011 19:38:53 +0000 (04:38 +0900)
committerPHO <pho@cielonegro.org>
Thu, 25 Aug 2011 19:38:53 +0000 (04:38 +0900)
Ditz-issue: 8959dadc07db1bd363283dee401073f6e48dc7fa

Network/HTTP/Lucu/Postprocess.hs

index ca416b9f4dc24b96cf5f206554c7d4a8bf212100..49c95e809be046489bed306c83db6f77eab12baf 100644 (file)
@@ -1,5 +1,6 @@
 {-# LANGUAGE
     BangPatterns
+  , DoAndIfThenElse
   , OverloadedStrings
   , UnicodeSyntax
   #-}
@@ -78,12 +79,18 @@ postprocess !itr
                           ⊕ printStatusCode sc )
 
          when (sc ≡ MethodNotAllowed ∧ getHeader "Allow" res ≡ Nothing)
-                  $ abortSTM InternalServerError []
-                        $ Just ("The status was " ++ show sc ++ " but no Allow header.")
+             $ abortSTM InternalServerError []
+             $ Just
+             $ A.toText ( "The status was "
+                          ⊕ printStatusCode sc
+                          ⊕ " but no Allow header." )
 
-         when (sc /= NotModified ∧ isRedirection sc ∧ getHeader (C8.pack "Location") res ≡ Nothing)
-                  $ abortSTM InternalServerError []
-                        $ Just ("The status code was " ++ show sc ++ " but no Location header.")
+         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
 
@@ -117,32 +124,34 @@ postprocess !itr
 
                if canHaveBody then
                    when (reqVer ≡ HttpVersion 1 1)
-                            $ do updateRes $ setHeader "Transfer-Encoding" "chunked"
-                                 writeItr itr itrWillChunkBody True
-                 else
+                       $ do updateRes $ setHeader "Transfer-Encoding" "chunked"
+                            writeItr itr itrWillChunkBody True
+               else
                    -- body 関連のヘッダを削除。但し HEAD なら Content-* は殘す
                    when (reqMethod req /= HEAD)
-                            $ do updateRes $ deleteHeader "Content-Type"
-                                 updateRes $ deleteHeader "Etag"
-                                 updateRes $ deleteHeader "Last-Modified"
+                       $ do updateRes $ deleteHeader "Content-Type"
+                            updateRes $ deleteHeader "Etag"
+                            updateRes $ deleteHeader "Last-Modified"
 
                conn ← readHeader "Connection"
                case conn of
                  Nothing    → return ()
                  Just value → when (A.toCIAscii value ≡ "close")
-                                   $ writeItr itr itrWillClose True
+                                  $ writeItr itr itrWillClose True
 
                willClose ← readItr itr itrWillClose id
                when willClose
-                        $ updateRes $ setHeader "Connection" "close"
+                   $ updateRes $ setHeader "Connection" "close"
 
                when (reqMethod req ≡ HEAD ∨ not canHaveBody)
-                        $ writeTVar (itrWillDiscardBody itr) True
+                   $ writeTVar (itrWillDiscardBody itr) True
 
       readHeader ∷ CIAscii → STM (Maybe Ascii)
+      {-# INLINE readHeader #-}
       readHeader = readItr itr itrResponse ∘ getHeader
 
       updateRes ∷ (Response → Response) → STM ()
+      {-# INLINE updateRes #-}
       updateRes = updateItr itr itrResponse
 
 completeUnconditionalHeaders ∷ Config → Response → IO Response