]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/Response.hs
Optimized as possible as I can.
[Lucu.git] / Network / HTTP / Lucu / Response.hs
index 9ca08be016a2c9509d5467c6e8f0111df6106358..913c491f6f1242373f4c52d9ef10a62a9ddd781e 100644 (file)
@@ -16,10 +16,10 @@ module Network.HTTP.Lucu.Response
     where
 
 import           Data.Dynamic
+import           Network.HTTP.Lucu.Format
 import           Network.HTTP.Lucu.Headers
 import           Network.HTTP.Lucu.HttpVersion
 import           System.IO
-import           Text.Printf
 
 -- |This is the definition of HTTP status code.
 -- 'Network.HTTP.Lucu.Resource.setStatus' accepts these named statuses
@@ -80,13 +80,13 @@ data StatusCode = Continue
 instance Show StatusCode where
     show sc = let (num, msg) = statusCode sc
               in
-                printf "%03d %s" num msg
+                (fmtDec 3 num) ++ " " ++ msg
 
 
 data Response = Response {
-      resVersion :: HttpVersion
-    , resStatus  :: StatusCode
-    , resHeaders :: Headers
+      resVersion :: !HttpVersion
+    , resStatus  :: !StatusCode
+    , resHeaders :: !Headers
     } deriving (Show, Eq)
 
 
@@ -96,16 +96,18 @@ instance HasHeaders Response where
 
 
 hPutResponse :: Handle -> Response -> IO ()
-hPutResponse h res = do hPutHttpVersion h (resVersion res)
-                        hPutChar        h ' '
-                        hPutStatus      h (resStatus  res)
-                        hPutStr         h "\r\n"
-                        hPutHeaders     h (resHeaders res)
+hPutResponse h res
+    = h `seq` res `seq`
+      do hPutHttpVersion h (resVersion res)
+         hPutChar        h ' '
+         hPutStatus      h (resStatus  res)
+         hPutStr         h "\r\n"
+         hPutHeaders     h (resHeaders res)
 
 hPutStatus :: Handle -> StatusCode -> IO ()
-hPutStatus h sc = let (num, msg) = statusCode sc
-                  in
-                    hPrintf h "%03d %s" num msg
+hPutStatus h sc
+    = h `seq` sc `seq`
+      hPutStr h (show sc)
 
 -- |@'isInformational' sc@ is True iff @sc < 200@.
 isInformational :: StatusCode -> Bool