]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/HttpVersion.hs
Implemented fallback handler.
[Lucu.git] / Network / HTTP / Lucu / HttpVersion.hs
index 38d0e5b81ad49767621098c06bb499f347bae175..9bc1b819bc743033440c275d0cde40fa9b9e8bbb 100644 (file)
@@ -8,13 +8,12 @@ module Network.HTTP.Lucu.HttpVersion
     )
     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
 
 -- |@'HttpVersion' major minor@ represents \"HTTP\/major.minor\".
-data HttpVersion = HttpVersion Int Int
+data HttpVersion = HttpVersion !Int !Int
                    deriving (Eq)
 
 instance Show HttpVersion where
@@ -34,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