diff options
author | Daniel Schadt <kingdread@gmx.de> | 2020-03-01 18:10:12 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2020-03-01 18:10:12 +0100 |
commit | 7f11cf1617aed8930598d7bd908ee1625cbc97f7 (patch) | |
tree | 2f799200a78e04817ed4b084255ee8479cc06371 | |
parent | 76771f6e87d23972b0e590e9811de5c1a4d4e5c7 (diff) | |
download | simghost-7f11cf1617aed8930598d7bd908ee1625cbc97f7.tar.gz simghost-7f11cf1617aed8930598d7bd908ee1625cbc97f7.tar.bz2 simghost-7f11cf1617aed8930598d7bd908ee1625cbc97f7.zip |
rewrite imgHostMain
The right-drift was not nice to look at, so we're now doing the dispatch
using a small helper method.
-rw-r--r-- | src/Lib.hs | 29 |
1 files changed, 20 insertions, 9 deletions
@@ -291,12 +291,23 @@ handleUpload = do -- Depending on the given parameters, this either dispatches to -- 'handleCleanup', 'handleUpload' or just returns the 'indexPage'. imgHostMain :: App CGIResult -imgHostMain = do - cleanup <- getInput "cleanup" - case cleanup of - Just _ -> handleCleanup - Nothing -> do - method <- requestMethod - case method of - "POST" -> handleUpload - _ -> output indexPage +imgHostMain = dispatch [ (doCleanup, handleCleanup) + , (doUpload, handleUpload) + , (doDefault, output indexPage) + ] + where + dispatch :: [(App Bool, App CGIResult)] -> App CGIResult + dispatch ((c, a):as) = do + take_that <- c + if take_that then a + else dispatch as + dispatch [] = do + setStatus 500 "Internal Server Error" + output "No dispatch could be done :(" + + doCleanup :: App Bool + doCleanup = isJust <$> getInput "cleanup" + doUpload :: App Bool + doUpload = ("POST" ==) <$> requestMethod + doDefault :: App Bool + doDefault = return True |