pgf-server HTTP mode feature: return the contents of index.html when the URL refers to a directory

This commit is contained in:
hallgren
2010-09-02 14:10:07 +00:00
parent c234222cd9
commit c5f0b31dbe

View File

@@ -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)