summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2010-09-02 14:10:07 +0000
committerhallgren <hallgren@chalmers.se>2010-09-02 14:10:07 +0000
commitb1bf971066022e8c41d33b353d0de3ba63c83247 (patch)
tree8e2fff0604bb2c0cbac3eded9acca74dd3f70757 /src
parentdaa726d74241c0a9688be45e9521a75f2e15b337 (diff)
pgf-server HTTP mode feature: return the contents of index.html when the URL refers to a directory
Diffstat (limited to 'src')
-rw-r--r--src/server/ServeStaticFile.hs6
1 files changed, 6 insertions, 0 deletions
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)