module Network.Types
(
Method(..)
, HttpVersion(..)
, http10
, http11
, Header(..)
, RequestUri(..)
, Request(..)
, Response(..)
, URI(..)
, URIAuth(..)
, HttpError(..)
) where
import Control.Exception as Ex
import Data.Typeable
import Data.ByteString.Char8 as C
data HttpVersion =
HttpVersion { httpMajor :: Int
, httpMinor :: Int
} deriving (Eq, Show)
http10 :: HttpVersion
http10 = HttpVersion 1 0
http11 :: HttpVersion
http11 = HttpVersion 1 1
data Header = GeneralHeader | RequestHeader | EntityHeader
data Method = GET
| HEAD
| POST
| PUT
| DELETE
| TRACE
| OPTIONS
| CONNECT
| EXTENSIONMETHOD ByteString
deriving (Eq, Show)
data Request =
Request {
rqMethod :: Method
, rqUri :: RequestUri
, rqVersion :: HttpVersion
, rqHeaders :: [(ByteString, ByteString)]
, rqBody :: ByteString
} deriving (Eq, Show)
data RequestUri = Asterisk
| AbsoluteUri URI
| AbsolutePath ByteString
| RelativeRef URI
| Authority (Maybe URIAuth)
deriving (Eq, Show)
data Response =
Response {
rpCode :: Int
, rpHeaders :: [(ByteString, ByteString)]
, rpVersion :: (Int,Int)
, rpMessage :: ByteString
} deriving (Eq, Show)
data URI = URI
{ uriScheme :: String
, uriAuthority :: Maybe URIAuth
, uriPath :: String
, uriQuery :: String
, uriFragment :: String
} deriving (Eq, Show)
data URIAuth = URIAuth
{ uriUserInfo :: String
, uriRegName :: String
, uriPort :: String
} deriving (Eq, Show)
nullURI :: URI
nullURI = URI
{ uriScheme = ""
, uriAuthority = Nothing
, uriPath = ""
, uriQuery = ""
, uriFragment = ""
}
data HttpError
= InvalidRequestError { httpErrorMessage :: String }
deriving (Eq, Typeable)
instance Exception HttpError
instance Show HttpError where
show (InvalidRequestError msg) = "Invalid HTTP request: " ++ msg