X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FResponse.hs;h=913c491f6f1242373f4c52d9ef10a62a9ddd781e;hb=858129cb755aa09da2b7bd758efb8519f2c89103;hp=9ca08be016a2c9509d5467c6e8f0111df6106358;hpb=30fcb38426696db8b80d322196cc594431e30407;p=Lucu.git diff --git a/Network/HTTP/Lucu/Response.hs b/Network/HTTP/Lucu/Response.hs index 9ca08be..913c491 100644 --- a/Network/HTTP/Lucu/Response.hs +++ b/Network/HTTP/Lucu/Response.hs @@ -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