From c5f0b31dbe507ef23b05040adbdce190bec4e1c2 Mon Sep 17 00:00:00 2001 From: hallgren Date: Thu, 2 Sep 2010 14:10:07 +0000 Subject: [PATCH] pgf-server HTTP mode feature: return the contents of index.html when the URL refers to a directory --- src/server/ServeStaticFile.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/server/ServeStaticFile.hs b/src/server/ServeStaticFile.hs index f2bbc3e81..748cb870d 100644 --- a/src/server/ServeStaticFile.hs +++ b/src/server/ServeStaticFile.hs @@ -1,9 +1,15 @@ module ServeStaticFile where import System.FilePath +import System.Directory(doesDirectoryExist) import Network.CGI(setHeader,outputFPS,liftIO) import qualified Data.ByteString.Lazy.Char8 as BS serveStaticFile path = + do b <- liftIO $ doesDirectoryExist path + let path' = if b then path "index.html" else path + serveStaticFile' path' + +serveStaticFile' path = do setHeader "Content-Type" (contentTypeFromExt (takeExtension path)) outputFPS =<< liftIO (BS.readFile path)