@@ -2,9 +2,14 @@
22{-# LANGUAGE TemplateHaskell, CPP #-}
33-- | Static file serving for WAI.
44module Network.Wai.Application.Static
5− ( -- * Generic, non-WAI code
5+ ( -- * WAI application
6+ staticApp
7+ -- ** Settings
8+ , StaticSettings (..)
9+ , defaultStaticSettings
10+ -- * Generic, non-WAI code
611 -- ** Mime types
7− MimeType
12+ , MimeType
813 , defaultMimeType
914 -- ** Mime type by file extension
1015 , Extension
@@ -16,25 +21,21 @@ module Network.Wai.Application.Static
1621 -- ** Finding files
1722 , Pieces
1823 , pathFromPieces
24+ , unfixPathName
1925 -- ** Directory listings
2026 , Listing
2127 , defaultListing
22− , defaultDirListing
23− -- * WAI application
24− , staticApp
25− , staticAppPieces
26− -- ** Settings
27− , StaticSettings (..)
28− , defaultStaticSettings
29− -- should be moved to common helper
30− , unfixPathName
31− -- new stuff to be sorted
28+ -- ** Lookup functions
3229 , fileSystemLookup
3330 , embeddedLookup
31+ -- ** Embedded
32+ , Embedded
33+ , EmbeddedEntry (..)
34+ , toEmbedded
35+ -- ** Redirecting
3436 , defaultMkRedirect
37+ -- * Other data types
3538 , File (..)
36− , toEmbedded
37− , StaticDirListing (..)
3839 , MaxAge (..)
3940 ) where
4041
@@ -311,14 +312,6 @@ checkPieces fileLookup indices pieces req ss
311312
312313type Listing = (Pieces -> Folder -> IO L.ByteString)
313314
314−data StaticDirListing = StaticDirListing {
315− ssListing :: Maybe Listing
316− , ssIndices :: [T.Text]
317−}
318−
319−defaultDirListing :: StaticDirListing
320−defaultDirListing = StaticDirListing (Just defaultListing) []
321−
322315oneYear :: Int
323316oneYear = 60 * 60 * 24 * 365
324317
@@ -326,7 +319,7 @@ type FileLookup = Maybe (Either Folder File)
326319
327320data Folder = Folder
328321 { folderName :: T.Text
329− , folderContents :: [Either Folder File] -- FIXME remove?
322+ , folderContents :: [Either Folder File]
330323 }
331324
332325data File = File
@@ -344,7 +337,8 @@ data StaticSettings = StaticSettings
344337 { ssFolder :: Pieces -> IO FileLookup
345338 , ssMkRedirect :: Pieces -> ByteString -> ByteString
346339 , ssGetMimeType :: File -> IO MimeType
347− , ssDirListing :: StaticDirListing
340+ , ssListing :: Maybe Listing
341+ , ssIndices :: [T.Text]
348342 , ssMaxAge :: MaxAge
349343 }
350344
@@ -364,8 +358,9 @@ defaultStaticSettings = StaticSettings
364358 { ssFolder = fileSystemLookup "static"
365359 , ssMkRedirect = defaultMkRedirect
366360 , ssGetMimeType = return . defaultMimeTypeByExt . T.unpack . fileName
367− , ssDirListing = defaultDirListing
368361 , ssMaxAge = MaxAgeSeconds $ 60 * 60
362+ , ssListing = Just defaultListing
363+ , ssIndices = ["index.html", "index.htm"]
369364 }
370365
371366fileHelper :: FilePath -> T.Text -> IO File
@@ -494,8 +489,7 @@ staticAppPieces _ _ req
494489 [("Content-Type", "text/plain")]
495490 "Only GET is supported"
496491staticAppPieces ss pieces req = liftIO $ do
497− let indices = case ssDirListing ss of
498− StaticDirListing _ is -> is
492+ let indices = ssIndices ss
499493 cp <- checkPieces (ssFolder ss) indices pieces req ss
500494 case cp of
501495 FileResponse file ch -> do
@@ -510,13 +504,13 @@ staticAppPieces ss pieces req = liftIO $ do
510504 [ ("Content-Type", "text/plain")
511505 ] "Not Modified"
512506 DirectoryResponse fp ->
513− case ssDirListing ss of
514− StaticDirListing (Just f) _ -> do
507+ case ssListing ss of
508+ (Just f) -> do
515509 lbs <- f pieces fp
516510 return $ W.responseLBS H.status200
517511 [ ("Content-Type", "text/html; charset=utf-8")
518512 ] lbs
519− StaticDirListing Nothing _ -> return $ W.responseLBS H.status403
513+ Nothing -> return $ W.responseLBS H.status403
520514 [ ("Content-Type", "text/plain")
521515 ] "Directory listings disabled"
522516 SendContent mt lbs -> do