X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FResponse.hs;h=a593b3ad928a6710e932edfd0a2711d8a9d80b59;hp=df98bf741c24481ed59cc468f47273657d72aa67;hb=3fe5ca3;hpb=db4b61223e0d8b34079d3b190fb3e3644b0b4866 diff --git a/Network/HTTP/Lucu/Response.hs b/Network/HTTP/Lucu/Response.hs index df98bf7..a593b3a 100644 --- a/Network/HTTP/Lucu/Response.hs +++ b/Network/HTTP/Lucu/Response.hs @@ -6,14 +6,13 @@ , UnicodeSyntax , ViewPatterns #-} -{-# OPTIONS_HADDOCK prune #-} -- |Definition of things related on HTTP response. module Network.HTTP.Lucu.Response ( StatusCode(..) , Response(..) , printStatusCode - , hPutResponse + , printResponse , isInformational , isSuccessful , isRedirection @@ -23,11 +22,10 @@ module Network.HTTP.Lucu.Response , statusCode ) where -import Data.Ascii (Ascii) +import Data.Ascii (Ascii, AsciiBuilder) import qualified Data.Ascii as A import Data.Monoid.Unicode import Data.Typeable -import Network.HTTP.Lucu.HandleLike import Network.HTTP.Lucu.Headers import Network.HTTP.Lucu.HttpVersion import Network.HTTP.Lucu.Utils @@ -89,11 +87,10 @@ data StatusCode = Continue | InsufficientStorage deriving (Eq, Show, Typeable) --- |Convert a 'StatusCode' to 'Ascii'. -printStatusCode ∷ StatusCode → Ascii +-- |Convert a 'StatusCode' to 'AsciiBuilder'. +printStatusCode ∷ StatusCode → AsciiBuilder printStatusCode (statusCode → (# num, msg #)) - = A.fromAsciiBuilder $ - ( show3 num ⊕ + = ( show3 num ⊕ A.toAsciiBuilder " " ⊕ A.toAsciiBuilder msg ) @@ -108,19 +105,14 @@ instance HasHeaders Response where getHeaders = resHeaders setHeaders res hdr = res { resHeaders = hdr } -hPutResponse ∷ HandleLike h ⇒ h → Response → IO () -hPutResponse h (Response {..}) - = do hPutHttpVersion h resVersion - hPutChar h ' ' - hPutStatus h resStatus - hPutBS h "\r\n" - hPutHeaders h resHeaders - -hPutStatus ∷ HandleLike h ⇒ h → StatusCode → IO () -hPutStatus h (statusCode → (# num, msg #)) - = do hPutBS h (A.toByteString $ A.fromAsciiBuilder $ show3 num) - hPutChar h ' ' - hPutBS h (A.toByteString msg) +-- |Convert a 'Response' to 'AsciiBuilder'. +printResponse ∷ Response → AsciiBuilder +printResponse (Response {..}) + = printHttpVersion resVersion ⊕ + A.toAsciiBuilder " " ⊕ + printStatusCode resStatus ⊕ + A.toAsciiBuilder "\x0D\x0A" ⊕ + printHeaders resHeaders -- |@'isInformational' sc@ is 'Prelude.True' iff @sc < 200@. isInformational ∷ StatusCode → Bool