]> gitweb @ CieloNegro.org - Lucu.git/blob - examples/Multipart.hs
multipart/form-data and more
[Lucu.git] / examples / Multipart.hs
1 import Data.List
2 import Data.Maybe
3 import Network
4 import Network.HTTP.Lucu
5
6 main :: IO ()
7 main = let config    = defaultConfig { cnfServerPort = PortNumber 9999 }
8            resources = mkResTree [ ([], resMain) ]
9        in
10          do putStrLn "Access http://localhost:9999/ with your browser."
11             runHttpd config resources
12
13
14 resMain :: ResourceDef
15 resMain 
16     = ResourceDef {
17         resUsesNativeThread = False
18       , resIsGreedy         = False
19       , resGet
20           = Just $ do setContentType $ read "text/html"
21                       output ("<title>Multipart Form Test</title>" ++
22                               "<form action=\"/\" method=\"post\" enctype=\"multipart/form-data\">" ++
23                               "  Enter some value:" ++
24                               "  <input type=\"text\" name=\"val\">" ++
25                               "  <input type=\"submit\" value=\"Submit\">" ++
26                               "</form>")
27       , resHead   = Nothing
28       , resPost
29           = Just $ do form <- inputForm defaultLimit
30                       let value = fromMaybe "" $ fmap snd $ find ((== "val") . fst) form
31                       setContentType $ read "text/plain"
32                       output ("You entered: " ++ value)
33       , resPut    = Nothing
34       , resDelete = Nothing
35       }