module Chu2.FFI where
import Data.ByteString (ByteString)
import Data.ByteString.Char8 (pack)
type Header = (,) ByteString ByteString
data RequestMethod =
OPTIONS
| GET
| HEAD
| POST
| PUT
| DELETE
| TRACE
| CONNECT
deriving (Show, Read, Eq)
data Status =
OK
| Created
| Accepted
| NoContent
| MultipleChoices
| MovedPermanently
| SeeOther
| NotModified
| MovedTemporarily
| BadRequest
| Unauthorized
| Forbidden
| NotFound
| MethodNotAllowed
| NotAcceptable
| Conflict
| Gone
| PreconditionFailed
| RequestEntityTooLarge
| RequestURItooLong
| UnsupportedMediaType
| NotImplemented
| ServiceUnavailable
deriving (Show)
type Headers = [Header]
type Chu2Errors = ByteString -> IO ()
data Chu2UrlScheme = HTTP | HTTPS
deriving (Show)
data Env = Env
{ requestMethod :: RequestMethod
, scriptName :: ByteString
, pathInfo :: ByteString
, queryString :: ByteString
, serverName :: ByteString
, serverPort :: ByteString
, httpHeaders :: Headers
, chu2Version :: ByteString
, chu2UrlScheme :: Chu2UrlScheme
, chu2Input :: ByteString
, chu2Errors :: Chu2Errors
, chu2Headers :: Headers
}
data Response = Response
{ status :: Status
, headers :: Headers
, body :: ByteString
}
deriving (Show)
type Application = Env -> IO Response