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
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)
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