module Network.IHttp.Types
(
HeaderMap,
HttpMethod(..),
HttpVersion(..),
Request(..),
Response(..),
HttpError(..)
)
where
import Control.Exception as Ex
import Data.ByteString (ByteString)
import Data.Map (Map)
import Data.Typeable
type HeaderMap = Map ByteString ByteString
data HttpError
= InvalidHeaderError { httpErrorMessage :: String }
| InvalidRequestError { httpErrorMessage :: String }
| InvalidResponseError { httpErrorMessage :: String }
| UnsupportedVersionError { httpErrorMessage :: String }
deriving (Eq, Typeable)
instance Exception HttpError
instance Show HttpError where
show (InvalidHeaderError msg) = "Invalid HTTP header: " ++ msg
show (InvalidRequestError msg) = "Invalid HTTP request: " ++ msg
show (InvalidResponseError msg) = "Invalid HTTP response: " ++ msg
show (UnsupportedVersionError msg) = "Unsupported HTTP version: " ++ msg
data HttpMethod
= ConnectMethod
| DeleteMethod
| GetMethod
| HeadMethod
| OptionsMethod
| PatchMethod
| PostMethod
| PutMethod
| TraceMethod
| XMethod ByteString
deriving (Eq, Read, Show)
data HttpVersion
= Http1_0
| Http1_1
deriving (Eq, Ord, Read, Show)
data Request =
Request {
requestHeaders :: HeaderMap,
requestMethod :: HttpMethod,
requestUri :: ByteString,
requestVersion :: HttpVersion
}
deriving (Eq, Read, Show)
data Response =
Response {
responseCode :: Int,
responseHeaders :: HeaderMap,
responseMessage :: ByteString,
responseVersion :: HttpVersion
}
deriving (Eq, Read, Show)