{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}

-- | Types and constants to describe the HTTP version.
module Network.HTTP.Types.Version (
    HttpVersion (..),
    http09,
    http10,
    http11,
    http20,
) where

import Data.Data (Data)
import Data.Typeable (Typeable)
import GHC.Generics (Generic)

-- | HTTP Version.
--
-- Note that the 'Show' instance is intended merely for debugging.
data HttpVersion = HttpVersion
    { HttpVersion -> Int
httpMajor :: !Int
    , HttpVersion -> Int
httpMinor :: !Int
    }
    deriving
        ( HttpVersion -> HttpVersion -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HttpVersion -> HttpVersion -> Bool
$c/= :: HttpVersion -> HttpVersion -> Bool
== :: HttpVersion -> HttpVersion -> Bool
$c== :: HttpVersion -> HttpVersion -> Bool
Eq
        , Eq HttpVersion
HttpVersion -> HttpVersion -> Bool
HttpVersion -> HttpVersion -> Ordering
HttpVersion -> HttpVersion -> HttpVersion
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: HttpVersion -> HttpVersion -> HttpVersion
$cmin :: HttpVersion -> HttpVersion -> HttpVersion
max :: HttpVersion -> HttpVersion -> HttpVersion
$cmax :: HttpVersion -> HttpVersion -> HttpVersion
>= :: HttpVersion -> HttpVersion -> Bool
$c>= :: HttpVersion -> HttpVersion -> Bool
> :: HttpVersion -> HttpVersion -> Bool
$c> :: HttpVersion -> HttpVersion -> Bool
<= :: HttpVersion -> HttpVersion -> Bool
$c<= :: HttpVersion -> HttpVersion -> Bool
< :: HttpVersion -> HttpVersion -> Bool
$c< :: HttpVersion -> HttpVersion -> Bool
compare :: HttpVersion -> HttpVersion -> Ordering
$ccompare :: HttpVersion -> HttpVersion -> Ordering
Ord
        , Typeable
        , -- | @since 0.12.4
          Typeable HttpVersion
HttpVersion -> DataType
HttpVersion -> Constr
(forall b. Data b => b -> b) -> HttpVersion -> HttpVersion
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> HttpVersion -> u
forall u. (forall d. Data d => d -> u) -> HttpVersion -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> HttpVersion -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HttpVersion -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> HttpVersion -> m HttpVersion
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HttpVersion -> m HttpVersion
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c HttpVersion
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HttpVersion -> c HttpVersion
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c HttpVersion)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c HttpVersion)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HttpVersion -> m HttpVersion
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HttpVersion -> m HttpVersion
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HttpVersion -> m HttpVersion
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HttpVersion -> m HttpVersion
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> HttpVersion -> m HttpVersion
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> HttpVersion -> m HttpVersion
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> HttpVersion -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> HttpVersion -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> HttpVersion -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> HttpVersion -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HttpVersion -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HttpVersion -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> HttpVersion -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> HttpVersion -> r
gmapT :: (forall b. Data b => b -> b) -> HttpVersion -> HttpVersion
$cgmapT :: (forall b. Data b => b -> b) -> HttpVersion -> HttpVersion
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c HttpVersion)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c HttpVersion)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c HttpVersion)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c HttpVersion)
dataTypeOf :: HttpVersion -> DataType
$cdataTypeOf :: HttpVersion -> DataType
toConstr :: HttpVersion -> Constr
$ctoConstr :: HttpVersion -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c HttpVersion
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c HttpVersion
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HttpVersion -> c HttpVersion
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HttpVersion -> c HttpVersion
Data
        , -- | @since 0.12.4
          forall x. Rep HttpVersion x -> HttpVersion
forall x. HttpVersion -> Rep HttpVersion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HttpVersion x -> HttpVersion
$cfrom :: forall x. HttpVersion -> Rep HttpVersion x
Generic
        )

-- | >>> show http11
-- "HTTP/1.1"
instance Show HttpVersion where
    show :: HttpVersion -> String
show (HttpVersion Int
major Int
minor) = String
"HTTP/" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Int
major forall a. [a] -> [a] -> [a]
++ String
"." forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Int
minor

-- | HTTP 0.9
http09 :: HttpVersion
http09 :: HttpVersion
http09 = Int -> Int -> HttpVersion
HttpVersion Int
0 Int
9

-- | HTTP 1.0
http10 :: HttpVersion
http10 :: HttpVersion
http10 = Int -> Int -> HttpVersion
HttpVersion Int
1 Int
0

-- | HTTP 1.1
http11 :: HttpVersion
http11 :: HttpVersion
http11 = Int -> Int -> HttpVersion
HttpVersion Int
1 Int
1

-- | HTTP 2.0
--
-- @since 0.10
http20 :: HttpVersion
http20 :: HttpVersion
http20 = Int -> Int -> HttpVersion
HttpVersion Int
2 Int
0