diff --git a/TODO b/TODO index c3062510..cabb808c 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,4 @@ Catch exceptions and return as 500 errors approot Request parameters without a request object? +More checking on parameters (minimum length etc) diff --git a/Web/Restful/Helpers/Static.hs b/Web/Restful/Helpers/Static.hs index d2e46614..3b84d2e3 100644 --- a/Web/Restful/Helpers/Static.hs +++ b/Web/Restful/Helpers/Static.hs @@ -16,14 +16,26 @@ module Web.Restful.Helpers.Static ( serveStatic , FileLookup + , fileLookupDir ) where import qualified Data.ByteString as B +import System.Directory (doesFileExist) +import Control.Applicative ((<$>)) import Web.Restful type FileLookup = FilePath -> IO (Maybe B.ByteString) +-- | A 'FileLookup' for files in a directory. +fileLookupDir :: FilePath -> FileLookup +fileLookupDir dir fp = do + let fp' = dir ++ '/' : fp -- FIXME incredibly insecure... + exists <- doesFileExist fp' + if exists + then Just <$> B.readFile fp' + else return Nothing + serveStatic :: FileLookup -> Verb -> Handler serveStatic fl Get = getStatic fl serveStatic _ _ = notFound diff --git a/restful.cabal b/restful.cabal index f88a2904..7005f940 100644 --- a/restful.cabal +++ b/restful.cabal @@ -36,7 +36,8 @@ library test-framework-hunit, HUnit, QuickCheck == 1.*, - enumerable >= 0.0.3 + enumerable >= 0.0.3, + directory >= 1 exposed-modules: Web.Restful, Web.Restful.Constants, Web.Restful.Request,