[Fencommits] fenserve: respond to POST with 303 See Other to the relevant resource
Tuukka Hastrup
Tuukka.Hastrup at iki.fi
Wed May 9 21:25:29 EEST 2007
Wed May 9 21:22:03 EEST 2007 Tuukka Hastrup <Tuukka.Hastrup at iki.fi>
* respond to POST with 303 See Other to the relevant resource
diff -rN -u old-fenserve/notetaker/Main.hs new-fenserve/notetaker/Main.hs
--- old-fenserve/notetaker/Main.hs 2007-05-09 21:25:29.000000000 +0300
+++ new-fenserve/notetaker/Main.hs 2007-05-09 21:25:29.000000000 +0300
@@ -197,15 +197,18 @@
renderTime t0 = printf "%02u:%02u" (ctHour t) (ctMin t)
where t = toUTCTime (TOD (fromIntegral t0) 0)
-bodyView (Body _) nick = renderLog nick True
-bodyView (Add p _) nick = page p nick
-bodyView (Edit p _) nick = page p nick
-bodyView (Move _ q) nick = page q nick
-bodyView (DeleteOne p) nick = page p nick
-bodyView (Delete p) nick = page p nick
-bodyView (MakeOwnPage p) nick = page p nick
-bodyView (Unpage p) nick = page p nick
-bodyView (Revert n) nick = page [] nick
+viewURI (Body _) nick = ("/lastlog?nick=" ++ nick, "lastlog" )
+viewURI (Add p _) nick = pageURI p nick
+viewURI (Edit p _) nick = pageURI p nick
+viewURI (Move _ q) nick = pageURI q nick
+viewURI (DeleteOne p) nick = pageURI p nick
+viewURI (Delete p) nick = pageURI p nick
+viewURI (MakeOwnPage p) nick = pageURI p nick
+viewURI (Unpage p) nick = pageURI p nick
+viewURI (Revert n) nick = pageURI [] nick
+
+pageURI p nick = ("/item/" ++ renderPath p ++ "?nick=" ++ nick,
+ "item " ++ renderPath p)
export path notes = concatMap f [0..length notes-1] where
f i | Note title own _ cs <- notes !! i =
@@ -224,15 +227,18 @@
respond $ plain $ export (readPath p) notes
, h ["dump"] GET $ ok $ \() () -> get >>= respond . plain . show
, h [""] GET $ ok $ \() nick -> page [] nick
- , h () POST $ ok $ \() (nick,line) -> do
+ , h () POST $ seeOther $ \() (nick,line) -> do
+ let respondRedirect uri anchor = respond
+ (uri, "<a href='"++uri++"'>"++anchor++"</a>")
if line == ":ll" then
- renderLog nick True
+ respondRedirect ("/lastlog?nick="++nick) "lastlog"
else if line == ":m" || ":m " `isPrefixOf` line then
- page (readPath (drop 2 line)) nick
+ uncurry respondRedirect $
+ pageURI (readPath (drop 2 line)) nick
else do
time <- getTime; let body = readBody line
modify (++[Line time (quote nick) body])
- bodyView body nick
+ uncurry respondRedirect $ viewURI body nick
, h () POST $ ok $ \() () -> respond "Huh."
, h (Prefix ["item"]) GET $ ok $ \[p] n -> page (readPath p) n
]
More information about the Fencommits
mailing list