1 module Network.HTTP.Lucu.Httpd
3 , mkResourceTable -- [ ([String], Resource ()) ] -> ResourceTable
4 , runHttpd -- Config -> ResourceTable -> IO ()
8 import Control.Concurrent
9 import qualified Data.ByteString.Lazy.Char8 as B
10 import Data.ByteString.Lazy.Char8 (ByteString)
14 import Network.HTTP.Lucu.Config
15 import Network.HTTP.Lucu.Parser
16 import Network.HTTP.Lucu.Request
17 import Network.HTTP.Lucu.Resource
18 import Network.HTTP.Lucu.Response
22 type ResourceTable = Map [String] (Resource ())
25 mkResourceTable :: [ ([String], Resource ()) ] -> ResourceTable
26 mkResourceTable = M.fromList
29 runHttpd :: Config -> ResourceTable -> IO ()
32 do so <- listenOn (cnfServerPort cnf)
35 loop :: Socket -> IO ()
37 = do (h, host, port) <- accept so
38 forkIO $ service h host port
42 service :: Handle -> HostName -> PortNumber -> IO ()
44 = do input <- B.hGetContents h
47 loop :: ByteString -> IO ()
48 loop input = case parse requestP input of