]> gitweb @ CieloNegro.org - Lucu.git/blob - examples/HelloWorld.hs
2fb9ed98ccf3a5b381431fa72477765a2351570c
[Lucu.git] / examples / HelloWorld.hs
1 import Control.Monad.Trans
2 import Data.Maybe
3 import Network
4 import Network.HTTP.Lucu.Config
5 import Network.HTTP.Lucu.ETag
6 import Network.HTTP.Lucu.Httpd
7 import Network.HTTP.Lucu.Parser
8 import Network.HTTP.Lucu.Parser.Http
9 import Network.HTTP.Lucu.Resource
10 import Network.HTTP.Lucu.Response
11 import Network.URI
12 import System.Posix.Signals
13 import System.Time
14
15 main :: IO ()
16 main = let config    = defaultConfig { cnfServerPort = PortNumber 9999 }
17            resources = mkResTree [ ([], helloWorld) ]
18        in
19          do installHandler sigPIPE Ignore Nothing
20             runHttpd config resources
21
22
23 helloWorld :: ResourceDef
24 helloWorld
25     = ResourceDef {
26         resUsesNativeThread = False
27       , resIsGreedy         = False
28       , resGet
29           = Just $ do time <- liftIO $ getClockTime
30                       foundEntity False "abcde" time
31                       setHeader "Content-Type" "text/plain"
32                       outputChunk "Hello, "
33                       outputChunk "World!\n"
34       , resHead   = Nothing
35       , resPost
36           = Just $ do str1 <- inputChunk 3
37                       str2 <- inputChunk 3
38                       str3 <- inputChunk 3
39                       setHeader "Content-Type" "text/plain"
40                       output ("[" ++ str1 ++ " - " ++ str2 ++ "#" ++ str3 ++ "]")
41       , resPut    = Nothing
42       , resDelete = Nothing
43       }