]> gitweb @ CieloNegro.org - Lucu.git/blob - examples/HelloWorld.hs
data/mime.types
[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.MIMEType
8 import Network.HTTP.Lucu.MIMEType.Guess
9 import Network.HTTP.Lucu.Parser
10 import Network.HTTP.Lucu.Parser.Http
11 import Network.HTTP.Lucu.Resource
12 import Network.HTTP.Lucu.Resource.Tree
13 import Network.HTTP.Lucu.Response
14 import Network.URI
15 import System.Posix.Signals
16 import System.Time
17
18 main :: IO ()
19 main = let config    = defaultConfig { cnfServerPort = PortNumber 9999 }
20            resources = mkResTree [ ([], helloWorld) ]
21        in
22          do installHandler sigPIPE Ignore Nothing
23             runHttpd config resources
24
25
26 helloWorld :: ResourceDef
27 helloWorld
28     = ResourceDef {
29         resUsesNativeThread = False
30       , resIsGreedy         = False
31       , resGet
32           = Just $ do time <- liftIO $ getClockTime
33                       foundEntity (strongETag "abcde") time
34                       setContentType $ "text" +/+ "hello"
35                       outputChunk "Hello, "
36                       outputChunk "World!\n"
37       , resHead   = Nothing
38       , resPost
39           = Just $ do str1 <- inputChunk 3
40                       str2 <- inputChunk 3
41                       str3 <- inputChunk 3
42                       setContentType $ "text" +/+ "hello"
43                       output ("[" ++ str1 ++ " - " ++ str2 ++ "#" ++ str3 ++ "]")
44       , resPut    = Nothing
45       , resDelete = Nothing
46       }