5 -- |An internal module for HTTP version numbers.
6 module Network.HTTP.Lucu.HttpVersion
12 import Control.Applicative
13 import Control.Applicative.Unicode
14 import Data.Ascii (AsciiBuilder)
15 import qualified Data.Ascii as A
16 import Data.Attoparsec.Char8
17 import Data.Monoid.Unicode
18 import Prelude hiding (min)
20 -- |An HTTP version consists of major and minor versions.
22 = HttpVersion !Int !Int
25 instance Ord HttpVersion where
26 (HttpVersion majA minA) `compare` (HttpVersion majB minB)
33 -- |Convert an 'HttpVersion' to 'AsciiBuilder'.
34 printHttpVersion ∷ HttpVersion → AsciiBuilder
37 -- Optimisation for special cases.
38 HttpVersion 1 0 → A.toAsciiBuilder "HTTP/1.0"
39 HttpVersion 1 1 → A.toAsciiBuilder "HTTP/1.1"
40 -- General (but almost never stumbling) cases.
42 → A.toAsciiBuilder "HTTP/" ⊕
43 A.toAsciiBuilder (A.unsafeFromString $ show maj) ⊕
44 A.toAsciiBuilder "." ⊕
45 A.toAsciiBuilder (A.unsafeFromString $ show min)
47 -- |'Parser' for an 'HttpVersion'.
48 httpVersion ∷ Parser HttpVersion
49 httpVersion = string "HTTP/"
51 (HttpVersion <$> decimal ⊛ (char '.' *> decimal))