]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/HttpVersion.hs
</> is better than +/+
[Lucu.git] / Network / HTTP / Lucu / HttpVersion.hs
index 88dc24e5b61673726da5f31e70d184e42b9cf48f..38d0e5b81ad49767621098c06bb499f347bae175 100644 (file)
@@ -1,15 +1,24 @@
+-- #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 (Show, Eq)
+                   deriving (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 +36,10 @@ httpVersionP = do string "HTTP/"
                   minor <- many1 digit
                   return $ HttpVersion (read major) (read minor)
 
+
+hPutHttpVersion :: Handle -> HttpVersion -> IO ()
+hPutHttpVersion h (HttpVersion maj min)
+    = do hPutStr  h "HTTP/"
+         hPutStr  h (show maj)
+         hPutChar h '.'
+         hPutStr  h (show min)
\ No newline at end of file