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