happstack-server-6.1.4: Web related tools and services.

Portabilityrequires mtl
MaintainerHappstack team <happs@googlegroups.com>




simpleHTTP is a self-contained HTTP server which can be used to run a ServerPart.

A very simple, "Hello World!" web app looks like:

 import Happstack.Server
 main = simpleHTTP nullConf $ ok "Hello World!"

By default the server will listen on port 8000. Run the app and point your browser at: http://localhost:8000/

For FastCGI support see: http://hackage.haskell.org/package/happstack-fastcgi



simpleHTTP :: ToMessage a => Conf -> ServerPartT IO a -> IO ()Source

start the server, and handle requests using the supplied ServerPart.

This function will not return, though it may throw an exception.

NOTE: The server will only listen on IPv4 due to portability issues in the Network module. For IPv6 support, use simpleHTTPWithSocket with custom socket.

simpleHTTP' :: (ToMessage b, Monad m, Functor m) => (UnWebT m a -> UnWebT IO b) -> Conf -> ServerPartT m a -> IO ()Source

A combination of simpleHTTP'' and mapServerPartT. See mapServerPartT for a discussion of the first argument of this function.

NOTE: This function always binds to IPv4 ports until Network module is fixed to support IPv6 in a portable way. Use simpleHTTPWithSocket with custom socket if you want different behaviour.

simpleHTTP'' :: (ToMessage b, Monad m, Functor m) => ServerPartT m b -> Request -> m ResponseSource

Generate a result from a ServerPartT and a Request. This is mainly used by CGI (and fast-cgi) wrappers.

simpleHTTPWithSocket :: ToMessage a => Socket -> Conf -> ServerPartT IO a -> IO ()Source

Run simpleHTTP with a previously bound socket. Useful if you want to run happstack as user on port 80. Use something like this:

 import System.Posix.User (setUserID, UserEntry(..), getUserEntryForName)

 main = do
     let conf = nullConf { port = 80 }
     socket <- bindPort conf
     -- do other stuff as root here
     getUserEntryForName "www" >>= setUserID . userID
     -- finally start handling incoming requests
     tid <- forkIO $ simpleHTTPWithSocket socket conf impl

Note: It's important to use the same conf (or at least the same port) for bindPort and simpleHTTPWithSocket.

see also: bindPort, bindIPv4

simpleHTTPWithSocket' :: (ToMessage b, Monad m, Functor m) => (UnWebT m a -> UnWebT IO b) -> Socket -> Conf -> ServerPartT m a -> IO ()Source

Like simpleHTTP' with a socket.

bindPort :: Conf -> IO SocketSource

Bind port and return the socket for use with simpleHTTPWithSocket. This function always binds to IPv4 ports until Network module is fixed to support IPv6 in a portable way.



:: String

IP address to bind to (must be an IP address and not a host name)

-> Int

port number to bind to

-> IO Socket 

parseConfig :: [String] -> Either [String] ConfSource

Parse command line options into a Conf.

Re-exported modules

Basic ServerMonad functionality

HTTP Realm Authentication

Create and Set Cookies (see also Happstack.Server.RqData)

Error Handling

Creating Responses

Request Routing


Looking up values in Query String, Request Body, and Cookies

Output Validation