X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FResponse.hs;h=9ca08be016a2c9509d5467c6e8f0111df6106358;hp=5a7c3a5fa2fe28a3ea5bd8b33ea97a64512892f0;hb=30fcb38426696db8b80d322196cc594431e30407;hpb=175e14b3b144537644e65ca76f1fca5c56fd44e9 diff --git a/Network/HTTP/Lucu/Response.hs b/Network/HTTP/Lucu/Response.hs index 5a7c3a5..9ca08be 100644 --- a/Network/HTTP/Lucu/Response.hs +++ b/Network/HTTP/Lucu/Response.hs @@ -1,12 +1,17 @@ +-- #prune + +-- |Definition of things related on HTTP response. module Network.HTTP.Lucu.Response ( StatusCode(..) , Response(..) - , hPutResponse -- Handle -> Response -> IO () - , isInformational -- StatusCode -> Bool - , isSuccessful -- StatusCode -> Bool - , isRedirection -- StatusCode -> Bool - , isError -- StatusCode -> Bool - , statusCode -- StatusCode -> (Int, String) + , hPutResponse + , isInformational + , isSuccessful + , isRedirection + , isError + , isClientError + , isServerError + , statusCode ) where @@ -16,6 +21,10 @@ 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 +-- so you don't have to memorize, for instance, that \"Gateway +-- Timeout\" is 504. data StatusCode = Continue | SwitchingProtocols | Processing @@ -98,25 +107,39 @@ hPutStatus h sc = let (num, msg) = statusCode sc in hPrintf h "%03d %s" num msg - +-- |@'isInformational' sc@ is True iff @sc < 200@. isInformational :: StatusCode -> Bool isInformational = doesMeet (< 200) +-- |@'isSuccessful' sc@ is True iff @200 <= sc < 300@. isSuccessful :: StatusCode -> Bool isSuccessful = doesMeet (\ n -> n >= 200 && n < 300) +-- |@'isRedirection' sc@ is True iff @300 <= sc < 400@. isRedirection :: StatusCode -> Bool isRedirection = doesMeet (\ n -> n >= 300 && n < 400) +-- |@'isError' sc@ is True iff @400 <= sc@ isError :: StatusCode -> Bool isError = doesMeet (>= 400) +-- |@'isClientError' sc@ is True iff @400 <= sc < 500@. +isClientError :: StatusCode -> Bool +isClientError = doesMeet (\ n -> n >= 400 && n < 500) + +-- |@'isServerError' sc@ is True iff @500 <= sc@. +isServerError :: StatusCode -> Bool +isServerError = doesMeet (>= 500) + + doesMeet :: (Int -> Bool) -> StatusCode -> Bool doesMeet p sc = let (num, _) = statusCode sc in p num +-- |@'statusCode' sc@ returns a tuple of numeric and textual +-- representation of @sc@. statusCode :: StatusCode -> (Int, String) statusCode Continue = (100, "Continue") statusCode SwitchingProtocols = (101, "Switching Protocols")