X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FHttpVersion.hs;h=c988aab3dcd99776547f61cf8a09471c09918957;hp=e0694f151d97db6a1ff3ddd44fa4c4a0293faf1d;hb=1196f43ecedbb123515065f0440844864af906fb;hpb=dfbf241202237b5b4033dbf781de5e10e0f919eb diff --git a/Network/HTTP/Lucu/HttpVersion.hs b/Network/HTTP/Lucu/HttpVersion.hs index e0694f1..c988aab 100644 --- a/Network/HTTP/Lucu/HttpVersion.hs +++ b/Network/HTTP/Lucu/HttpVersion.hs @@ -1,4 +1,4 @@ --- #prune +{-# OPTIONS_HADDOCK prune #-} -- |Manipulation of HTTP version string. module Network.HTTP.Lucu.HttpVersion @@ -30,21 +30,30 @@ instance Ord HttpVersion where httpVersionP :: Parser HttpVersion -httpVersionP = do string "HTTP/" - major <- many1 digit - char '.' - minor <- many1 digit - return $ HttpVersion (read' major) (read' minor) - where - read' "1" = 1 -- この二つが - read' "0" = 0 -- 壓倒的に頻出する - read' s = read s +httpVersionP = string "HTTP/" + >> + -- 頻出するので高速化 + choice [ do string "1.0" + return $ HttpVersion 1 0 + , do string "1.1" + return $ HttpVersion 1 1 + -- 一般の場合 + , do major <- many1 digit + char '.' + minor <- many1 digit + return $ HttpVersion (read major) (read minor) + ] hPutHttpVersion :: Handle -> HttpVersion -> IO () -hPutHttpVersion h (HttpVersion maj min) - = 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 +hPutHttpVersion !h !v + = case v of + -- 頻出するので高速化 + HttpVersion 1 0 -> C8.hPut h (C8.pack "HTTP/1.0") + HttpVersion 1 1 -> C8.hPut h (C8.pack "HTTP/1.1") + -- 一般の場合 + HttpVersion !maj !min + -> do C8.hPut h (C8.pack "HTTP/") + hPutStr h (show maj) + hPutChar h '.' + hPutStr h (show min)