]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/HttpVersion.hs
Use base64-bytestring instead of dataenc
[Lucu.git] / Network / HTTP / Lucu / HttpVersion.hs
index c988aab3dcd99776547f61cf8a09471c09918957..d48f6ec8c58f3d5009c3038ed500eb4e863e5003 100644 (file)
@@ -1,3 +1,7 @@
+{-# LANGUAGE
+    BangPatterns
+  , UnicodeSyntax
+  #-}
 {-# OPTIONS_HADDOCK prune #-}
 
 -- |Manipulation of HTTP version string.
@@ -9,9 +13,9 @@ module Network.HTTP.Lucu.HttpVersion
     where
 
 import qualified Data.ByteString.Char8 as C8
+import           Network.HTTP.Lucu.HandleLike
 import           Network.HTTP.Lucu.Parser
 import           Prelude hiding (min)
-import           System.IO
 
 -- |@'HttpVersion' major minor@ represents \"HTTP\/major.minor\".
 data HttpVersion = HttpVersion !Int !Int
@@ -33,27 +37,25 @@ httpVersionP :: Parser HttpVersion
 httpVersionP = string "HTTP/"
                >>
                -- 頻出するので高速化
-               choice [ do string "1.0"
-                           return $ HttpVersion 1 0
-                      , do string "1.1"
-                           return $ HttpVersion 1 1
+               choice [ string "1.0" >> return (HttpVersion 1 0)
+                      , string "1.1" >> return (HttpVersion 1 1)
                         -- 一般の場合
                       , do major <- many1 digit
-                           char '.'
+                           _     <- char '.'
                            minor <- many1 digit
                            return $ HttpVersion (read major) (read minor)
                       ]
 
 
-hPutHttpVersion :: Handle -> HttpVersion -> IO ()
+hPutHttpVersion :: HandleLike h => h -> HttpVersion -> IO ()
 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 1 0 -> hPutBS h (C8.pack "HTTP/1.0")
+        HttpVersion 1 1 -> hPutBS h (C8.pack "HTTP/1.1")
         -- 一般の場合
         HttpVersion !maj !min
-            -> do C8.hPut  h (C8.pack "HTTP/")
+            -> do hPutBS   h (C8.pack "HTTP/")
                   hPutStr  h (show maj)
                   hPutChar h '.'
                   hPutStr  h (show min)