X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FHttpVersion.hs;h=e1ed0f38024fd9836629c84eee5d9bef20fd46cc;hb=8e78bc83bfe67a376293c346ae0b30f1a684c787;hp=88dc24e5b61673726da5f31e70d184e42b9cf48f;hpb=9961a721f98b101825ef154a2122c1fc2fa6d1ac;p=Lucu.git diff --git a/Network/HTTP/Lucu/HttpVersion.hs b/Network/HTTP/Lucu/HttpVersion.hs index 88dc24e..e1ed0f3 100644 --- a/Network/HTTP/Lucu/HttpVersion.hs +++ b/Network/HTTP/Lucu/HttpVersion.hs @@ -1,15 +1,22 @@ +-- #prune + +-- |Manipulation of HTTP version string. module Network.HTTP.Lucu.HttpVersion ( HttpVersion(..) - , httpVersionP -- Parser HttpVersion + , httpVersionP + , hPutHttpVersion ) where -import qualified Data.ByteString.Lazy.Char8 as B -import Data.ByteString.Lazy.Char8 (ByteString) import Network.HTTP.Lucu.Parser +import System.IO + +-- |@'HttpVersion' major minor@ represents \"HTTP\/major.minor\". +data HttpVersion = HttpVersion !Int !Int + deriving (Eq) -data HttpVersion = HttpVersion Int Int - deriving (Show, Eq) +instance Show HttpVersion where + show (HttpVersion maj min) = "HTTP/" ++ show maj ++ "." ++ show min instance Ord HttpVersion where (HttpVersion majA minA) `compare` (HttpVersion majB minB) @@ -27,3 +34,11 @@ httpVersionP = do string "HTTP/" minor <- many1 digit return $ HttpVersion (read major) (read minor) + +hPutHttpVersion :: Handle -> HttpVersion -> IO () +hPutHttpVersion h (HttpVersion maj min) + = h `seq` + do hPutStr h "HTTP/" + hPutStr h (show maj) + hPutChar h '.' + hPutStr h (show min) \ No newline at end of file