-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Library for building servers with IterIO -- -- This module contains a set of generic building blocks for building -- servers with IterIO. @package iterio-server @version 0.1 -- | Generic building blocks for creating TCP Servers based on -- IterIO module Data.IterIO.Server.TCPServer -- | TCPServer holds all the information necessary to run bind to a -- sock and respond to TCP requests from the network. data TCPServer inp m TCPServer :: PortNumber -> Inum inp inp m () -> (Socket -> m (Iter inp m (), Onum inp m ())) -> (m () -> IO ()) -> TCPServer inp m -- | The TCP port the server will listen for incomming connections on. serverPort :: TCPServer inp m -> PortNumber -- | This Inum implements the actual functionality of the server. -- The input and output of the Inum correspond to the input and -- output of the socket. serverHandler :: TCPServer inp m -> Inum inp inp m () -- | A function to transform an accept incomming connection into an iter -- and onum. Most servers should just use defaultSocketAcceptor -- but this can be used for special cases, e.g. accepting SSL connections -- with Data.IterIO.SSL.iterSSL. serverAcceptor :: TCPServer inp m -> Socket -> m (Iter inp m (), Onum inp m ()) -- | Must execute the monadic result. Servers operating in the IO -- Monad can use id. serverResultHandler :: TCPServer inp m -> m () -> IO () -- | Runs a TCPServer in a loop. runTCPServer :: (ListLikeIO inp e, ChunkData inp, Monad m) => TCPServer inp m -> IO () -- | This acceptor creates an Iter and Onum using -- handleI and enumHandle respectively. defaultServerAcceptor :: (ListLikeIO inp e, ChunkData inp, MonadIO m) => Socket -> m (Iter inp m (), Onum inp m a) -- | For convenience, a TCPServer in the IO Monad with null -- defaults: -- -- minimalTCPServer :: (ListLikeIO inp e, ChunkData inp) => TCPServer inp IO -- | Creates a simple HTTP server from an HTTPRequestHandler. simpleHttpServer :: PortNumber -> HttpRequestHandler IO () -> TCPServer ByteString IO -- | Creates a TCPServer that echoes each line from the client until -- EOF. echoServer :: PortNumber -> TCPServer String IO instance Show (TCPServer inp m) -- | Utility functions for routing. module Data.IterIO.Http.Support.Routing -- | Like runHttpRoute but replaces GET and POST -- request headers with the value of the X-HTTP-Method-Override -- HTTP header if it is present. This allows applicaitons to respond to -- DELETE and PUT methods even though many browsers do -- not support those methods. runLHttpRoute :: Monad m => HttpRoute m s -> HttpReq s -> Iter ByteString m (HttpResp m) -- | Defines the Action monad which abstracts some of the details of -- handling HTTP requests with IterIO. module Data.IterIO.Http.Support.Action -- | A StateT monad in which requests can be handled. It keeps track -- of the HttpReq, the form parameters from the request body and -- an HttpResp used to reply to the client. type Action t m a = StateT (HttpReq t, HttpResp m, [Param]) m a -- | A request parameter from a form field in the HTTP body data Param Param :: ByteString -> ByteString -> [(ByteString, ByteString)] -> Param paramKey :: Param -> ByteString paramValue :: Param -> ByteString -- | Header of a multipart/form-data post paramHeaders :: Param -> [(ByteString, ByteString)] -- | Routes an Action routeAction :: Monad m => Action t m () -> HttpRoute m t -- | Routes an Action to the given URL pattern. Patterns can include -- directories as well as variable patterns (prefixed with :) to -- be passed into the Action as extra Params. Some examples -- of URL patters: -- -- routeActionPattern :: Monad m => String -> Action t m () -> HttpRoute m t -- | Returns a list of all Params. params :: Monad m => Action t m ([Param]) -- | Returns the Param corresponding to the specified key or -- Nothing if one is not present in the request. param :: Monad m => ByteString -> Action t m (Maybe Param) -- | Returns the HttpReq for the current request. getHttpReq :: Monad m => Action t m (HttpReq t) -- | Sets a the value for "_sess" in the cookie to the given string. setSession :: Monad m => String -> Action t m () -- | Removes the "_sess" key-value pair from the cookie. destroySession :: Monad m => Action t m () -- | Returns the value of an Http Header from the request if it exists -- otherwise Nothing requestHeader :: Monad m => ByteString -> Action t m (Maybe ByteString) -- | Utility functions for responding to HTTP requests from within an -- Action. module Data.IterIO.Http.Support.Responses -- | Responds to the client with a 200 (Success) response with the -- given body and mime-type. render :: Monad m => String -> ByteString -> Action t m () -- | Responds to the client with a 303 (Temporary Redirect) -- response to the given path. redirectTo :: Monad m => String -> Action t m () -- | Responds to the client with an empty 404 (Not Found) -- response. respond404 :: Monad m => Action t m () -- | Replaces the HTTP status in the current HttpResp with the given -- HttpStatus. respondStat :: Monad m => HttpStatus -> Action t m () -- | This module defines the RestController class module Data.IterIO.Http.Support.RestController -- | The class RestController allows a set of actions to be routed -- using RESTful HTTP verbs. class RestController a restIndex :: (RestController a, Monad m) => a -> Action t m () restShow :: (RestController a, Monad m) => a -> ByteString -> Action t m () restNew :: (RestController a, Monad m) => a -> Action t m () restCreate :: (RestController a, Monad m) => a -> Action t m () restEdit :: (RestController a, Monad m) => a -> ByteString -> Action t m () restUpdate :: (RestController a, Monad m) => a -> ByteString -> Action t m () restDestroy :: (RestController a, Monad m) => a -> ByteString -> Action t m () -- | Routes URLs under the given String to actions in a -- RestController. For example -- --
--   routeRestController posts myRestController
--   
-- -- will map the follwoing URLs: -- -- routeRestController :: (Monad m, RestController a) => String -> a -> HttpRoute m t