X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FHttpVersion.hs;fp=Network%2FHTTP%2FLucu%2FHttpVersion.hs;h=2029a7facbaf3e5eec5a1bc42201a74e26ff9151;hb=9668dc27a02b59d7bfb1e9e40af3d2619700ad69;hp=9ad1c0a07ccd964d9cdcee554ff604a5c558856d;hpb=f402841101b4b84f263eea1a43c848f81c48ff93;p=Lucu.git diff --git a/Network/HTTP/Lucu/HttpVersion.hs b/Network/HTTP/Lucu/HttpVersion.hs index 9ad1c0a..2029a7f 100644 --- a/Network/HTTP/Lucu/HttpVersion.hs +++ b/Network/HTTP/Lucu/HttpVersion.hs @@ -2,11 +2,12 @@ OverloadedStrings , UnicodeSyntax #-} --- |Manipulation of HTTP version string. +-- |HTTP version number module Network.HTTP.Lucu.HttpVersion ( HttpVersion(..) - , httpVersionP , printHttpVersion + + , httpVersionP ) where import qualified Blaze.Text.Int as BT @@ -18,7 +19,7 @@ import Data.Attoparsec.Char8 import Data.Monoid.Unicode import Prelude hiding (min) --- |@'HttpVersion' major minor@ represents \"HTTP\/major.minor\". +-- |An HTTP version consists of major and minor versions. data HttpVersion = HttpVersion !Int !Int deriving (Eq, Show) @@ -31,24 +32,25 @@ instance Ord HttpVersion where | minA < minB = LT | otherwise = EQ -httpVersionP ∷ Parser HttpVersion -httpVersionP = string "HTTP/" - *> - choice [ string "1.1" *> pure (HttpVersion 1 1) - , string "1.0" *> pure (HttpVersion 1 0) - , HttpVersion <$> decimal ⊛ (char '.' *> decimal) - ] - -- |Convert an 'HttpVersion' to 'AsciiBuilder'. printHttpVersion ∷ HttpVersion → AsciiBuilder printHttpVersion v = case v of - -- 頻出するので高速化 + -- Optimisation for special cases. HttpVersion 1 0 → A.toAsciiBuilder "HTTP/1.0" HttpVersion 1 1 → A.toAsciiBuilder "HTTP/1.1" - -- 一般の場合 + -- General cases. HttpVersion maj min → A.toAsciiBuilder "HTTP/" ⊕ A.unsafeFromBuilder (BT.integral maj) ⊕ A.toAsciiBuilder "." ⊕ A.unsafeFromBuilder (BT.integral min) + +-- |'Parser' for an 'HttpVersion'. +httpVersionP ∷ Parser HttpVersion +httpVersionP = string "HTTP/" + *> + choice [ string "1.1" *> pure (HttpVersion 1 1) + , string "1.0" *> pure (HttpVersion 1 0) + , HttpVersion <$> decimal ⊛ (char '.' *> decimal) + ]