blunt 0.0.2 → 0.0.3
raw patch · 3 files changed
+18/−8 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Blunt: safePointfree :: String -> IO (Maybe String)
Files
- CHANGELOG.md +4/−0
- blunt.cabal +1/−1
- library/Blunt.hs +13/−7
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Change log +## v0.0.3 (2015-03-19)++- Prevent `pointfree'` from throwing errors during a request.+ ## v0.0.2 (2015-03-18) - Added a rudimentary user interface.
blunt.cabal view
@@ -1,5 +1,5 @@ name: blunt-version: 0.0.2+version: 0.0.3 cabal-version: >=1.10 build-type: Simple license: MIT
library/Blunt.hs view
@@ -4,6 +4,7 @@ import Paths_blunt (getDataFileName) +import Control.Exception (SomeException, evaluate, handle) import Data.ByteString.Char8 (unpack) import Data.ByteString.Lazy (fromStrict) import Data.ByteString.Lazy.Char8 (pack)@@ -18,21 +19,26 @@ index <- getDataFileName "index.html" let method = requestMethod request path = pathInfo request- response = case (method, path) of- ("GET", []) -> responseFile+ response <- case (method, path) of+ ("GET", []) -> return $ responseFile ok200 [("Content-Type", "text/html; charset=utf-8")] index Nothing- ("GET", ["pointfree"]) ->+ ("GET", ["pointfree"]) -> do let params = queryString request input = case lookup "input" params of Just (Just param) -> param _ -> ""- maybeOutput = pointfree' (unpack input)- body = case maybeOutput of+ maybeOutput <- safePointfree (unpack input)+ let body = case maybeOutput of Just output -> pack output Nothing -> fromStrict input- in responseLBS ok200 [("Content-Type", "text/plain; charset=utf-8")] body- _ -> responseLBS notFound404 [] ""+ return $ responseLBS ok200 [("Content-Type", "text/plain; charset=utf-8")] body+ _ -> return $ responseLBS notFound404 [] "" respond response++safePointfree :: String -> IO (Maybe String)+safePointfree = handle handler . evaluate . pointfree' where+ handler :: SomeException -> IO (Maybe String)+ handler _ = return Nothing