X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FHttpVersion.hs;h=9bc1b819bc743033440c275d0cde40fa9b9e8bbb;hb=50e8fe7af585a8d33d93b3721be8f8f01905b891;hp=9b955d37fd9644beb912feb1808a1f2982dd97b9;hpb=3c7a58ab749a55a30466a033b170536bcdf18b98;p=Lucu.git diff --git a/Network/HTTP/Lucu/HttpVersion.hs b/Network/HTTP/Lucu/HttpVersion.hs index 9b955d3..9bc1b81 100644 --- a/Network/HTTP/Lucu/HttpVersion.hs +++ b/Network/HTTP/Lucu/HttpVersion.hs @@ -1,16 +1,19 @@ +-- #prune + +-- |Manipulation of HTTP version string. module Network.HTTP.Lucu.HttpVersion ( HttpVersion(..) - , httpVersionP -- Parser HttpVersion - , hPutHttpVersion -- Handle -> HttpVersion -> IO () + , httpVersionP + , hPutHttpVersion ) where -import qualified Data.ByteString.Lazy.Char8 as B -import Data.ByteString.Lazy.Char8 (ByteString) +import qualified Data.ByteString.Char8 as C8 import Network.HTTP.Lucu.Parser import System.IO -data HttpVersion = HttpVersion Int Int +-- |@'HttpVersion' major minor@ represents \"HTTP\/major.minor\". +data HttpVersion = HttpVersion !Int !Int deriving (Eq) instance Show HttpVersion where @@ -30,12 +33,17 @@ httpVersionP = do string "HTTP/" major <- many1 digit char '.' minor <- many1 digit - return $ HttpVersion (read major) (read minor) + return $ HttpVersion (read' major) (read' minor) + where + read' "1" = 1 -- この二つが + read' "0" = 0 -- 壓倒的に頻出する + read' s = read s hPutHttpVersion :: Handle -> HttpVersion -> IO () hPutHttpVersion h (HttpVersion maj min) - = do hPutStr h "HTTP/" + = h `seq` + do C8.hPut h (C8.pack "HTTP/") hPutStr h (show maj) hPutChar h '.' hPutStr h (show min) \ No newline at end of file