-
-httpVersionP :: Parser HttpVersion
-httpVersionP = do string "HTTP/"
- major <- many1 digit
- char '.'
- minor <- many1 digit
- return $ HttpVersion (read major) (read minor)
-
-
-hPutHttpVersion :: Handle -> HttpVersion -> IO ()
-hPutHttpVersion h (HttpVersion maj min)
- = do hPutStr h "HTTP/"
- hPutStr h (show maj)
- hPutChar h '.'
- hPutStr h (show min)
\ No newline at end of file
+httpVersionP ∷ Parser HttpVersion
+httpVersionP = string "HTTP/"
+ ≫
+ choice [ string "1.1" ≫ return (HttpVersion 1 1)
+ , string "1.0" ≫ return (HttpVersion 1 0)
+ , do major ← decimal
+ _ ← char '.'
+ minor ← decimal
+ return $ HttpVersion major minor
+ ]
+
+hPutHttpVersion ∷ HandleLike h ⇒ h → HttpVersion → IO ()
+hPutHttpVersion !h !v
+ = case v of
+ -- 頻出するので高速化
+ HttpVersion 1 0 → hPutBS h "HTTP/1.0"
+ HttpVersion 1 1 → hPutBS h "HTTP/1.1"
+ -- 一般の場合
+ HttpVersion !maj !min
+ → do hPutBS h "HTTP/"
+ hPutStr h (show maj)
+ hPutChar h '.'
+ hPutStr h (show min)