X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FResponse.hs;h=c18819f8f8ceb782a7e1938f3121c7a5d887beab;hb=fffa09842d060c7d738084125dea07783d84aefe;hp=cfff8197ddbaea7ea17d3d55be11398f8a76c714;hpb=51eda5b02d4528e2e240cbfc228de02b1c83799a;p=Lucu.git diff --git a/Network/HTTP/Lucu/Response.hs b/Network/HTTP/Lucu/Response.hs index cfff819..c18819f 100644 --- a/Network/HTTP/Lucu/Response.hs +++ b/Network/HTTP/Lucu/Response.hs @@ -10,14 +10,18 @@ module Network.HTTP.Lucu.Response StatusCode(..) , SomeStatusCode(..) , Response(..) + , statusCodes , module Network.HTTP.Lucu.StatusCode -- * Functions , emptyResponse + , setStatusCode , resCanHaveBody , printStatusCode , printResponse + , (≈) + , (≉) , isInformational , isSuccessful , isRedirection @@ -60,16 +64,23 @@ emptyResponse sc , resHeaders = (∅) } +-- |@'setStatusCode' sc res@ sets the status code of @res@ to @sc@. +setStatusCode ∷ StatusCode sc ⇒ sc → Response → Response +setStatusCode sc res + = res { + resStatus = fromStatusCode sc + } + -- |Returns 'True' iff a given 'Response' allows the existence of -- response entity body. resCanHaveBody ∷ Response → Bool {-# INLINEABLE resCanHaveBody #-} resCanHaveBody (Response {..}) - | isInformational resStatus = False - | toStatusCode resStatus ≡ Just NoContent = False - | toStatusCode resStatus ≡ Just ResetContent = False - | toStatusCode resStatus ≡ Just NotModified = False - | otherwise = True + | isInformational resStatus = False + | resStatus ≈ NoContent = False + | resStatus ≈ ResetContent = False + | resStatus ≈ NotModified = False + | otherwise = True -- |Convert a 'Response' to 'AsciiBuilder'. printResponse ∷ Response → AsciiBuilder @@ -81,32 +92,32 @@ printResponse (Response {..}) A.toAsciiBuilder "\x0D\x0A" ⊕ printHeaders resHeaders --- |@'isInformational' sc@ returns 'True' iff @sc < 200@. +-- |@'isInformational' sc@ returns 'True' iff @sc '<' 200@. isInformational ∷ StatusCode sc ⇒ sc → Bool {-# INLINE isInformational #-} isInformational = satisfy (< 200) --- |@'isSuccessful' sc@ returns 'True' iff @200 <= sc < 300@. +-- |@'isSuccessful' sc@ returns 'True' iff @200 '<=' sc '<' 300@. isSuccessful ∷ StatusCode sc ⇒ sc → Bool {-# INLINE isSuccessful #-} isSuccessful = satisfy (\ n → n ≥ 200 ∧ n < 300) --- |@'isRedirection' sc@ returns 'True' iff @300 <= sc < 400@. +-- |@'isRedirection' sc@ returns 'True' iff @300 '<=' sc '<' 400@. isRedirection ∷ StatusCode sc ⇒ sc → Bool {-# INLINE isRedirection #-} isRedirection = satisfy (\ n → n ≥ 300 ∧ n < 400) --- |@'isError' sc@ returns 'True' iff @400 <= sc@ +-- |@'isError' sc@ returns 'True' iff @400 '<=' sc@ isError ∷ StatusCode sc ⇒ sc → Bool {-# INLINE isError #-} isError = satisfy (≥ 400) --- |@'isClientError' sc@ returns 'True' iff @400 <= sc < 500@. +-- |@'isClientError' sc@ returns 'True' iff @400 '<=' sc '<' 500@. isClientError ∷ StatusCode sc ⇒ sc → Bool {-# INLINE isClientError #-} isClientError = satisfy (\ n → n ≥ 400 ∧ n < 500) --- |@'isServerError' sc@ returns 'True' iff @500 <= sc@. +-- |@'isServerError' sc@ returns 'True' iff @500 '<=' sc@. isServerError ∷ StatusCode sc ⇒ sc → Bool {-# INLINE isServerError #-} isServerError = satisfy (≥ 500)