]> gitweb @ CieloNegro.org - Lucu.git/blob - examples/HelloWorld.hs
928dab9fcfc976cab1360b1ceafde01f8b43c76a
[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.HTTP.Lucu.StaticFile
15 import Network.URI
16 import System.Time
17
18 main :: IO ()
19 main = let config    = defaultConfig { cnfServerPort = PortNumber 9999 }
20            resources = mkResTree [ ( []
21                                    , helloWorld )
22
23                                  , ( ["urandom"]
24                                    , staticFile "/dev/urandom" )
25
26                                  , ( ["inc"]
27                                    , staticDir "/usr/include" )
28                                  ]
29        in
30          runHttpd config resources
31
32
33 helloWorld :: ResourceDef
34 helloWorld
35     = ResourceDef {
36         resUsesNativeThread = False
37       , resIsGreedy         = False
38       , resGet
39           = Just $ do --time <- liftIO $ getClockTime
40                       --foundEntity (strongETag "abcde") time
41                       setContentType $ "text" </> "hello"
42                       outputChunk "Hello, "
43                       outputChunk "World!\n"
44       , resHead   = Nothing
45       , resPost
46           = Just $ do str1 <- inputChunk 3
47                       str2 <- inputChunk 3
48                       str3 <- inputChunk 3
49                       setContentType $ "text" </> "hello"
50                       output ("[" ++ str1 ++ " - " ++ str2 ++ "#" ++ str3 ++ "]")
51       , resPut    = Nothing
52       , resDelete = Nothing
53       }