]> gitweb @ CieloNegro.org - Lucu.git/blob - Network/HTTP/Lucu/HttpVersion.hs
Supplession of unneeded imports
[Lucu.git] / Network / HTTP / Lucu / HttpVersion.hs
1 -- #prune
2
3 -- |Manipulation of HTTP version string.
4 module Network.HTTP.Lucu.HttpVersion
5     ( HttpVersion(..)
6     , httpVersionP
7     , hPutHttpVersion
8     )
9     where
10
11 import           Network.HTTP.Lucu.Parser
12 import           System.IO
13
14 -- |@'HttpVersion' major minor@ represents \"HTTP\/major.minor\".
15 data HttpVersion = HttpVersion !Int !Int
16                    deriving (Eq)
17
18 instance Show HttpVersion where
19     show (HttpVersion maj min) = "HTTP/" ++ show maj ++ "." ++ show min
20
21 instance Ord HttpVersion where
22     (HttpVersion majA minA) `compare` (HttpVersion majB minB)
23         | majA > majB = GT
24         | majA < majB = LT
25         | minA > minB = GT
26         | minA < minB = LT
27         | otherwise   = EQ
28
29
30 httpVersionP :: Parser HttpVersion
31 httpVersionP = do string "HTTP/"
32                   major <- many1 digit
33                   char '.'
34                   minor <- many1 digit
35                   return $ HttpVersion (read major) (read minor)
36
37
38 hPutHttpVersion :: Handle -> HttpVersion -> IO ()
39 hPutHttpVersion h (HttpVersion maj min)
40     = h `seq`
41       do hPutStr  h "HTTP/"
42          hPutStr  h (show maj)
43          hPutChar h '.'
44          hPutStr  h (show min)