+-- | Handling static files on the filesystem.
module Network.HTTP.Lucu.StaticFile
( staticFile
, handleStaticFile
import Text.Printf
+-- | @'staticFile' fpath@ is a
+-- 'Network.HTTP.Lucu.Resource.Tree.ResourceDef' which serves the file
+-- at @fpath@ on the filesystem.
staticFile :: FilePath -> ResourceDef
staticFile path
= ResourceDef {
, resDelete = Nothing
}
-
+-- | Computation of @'handleStaticFile' fpath@ serves the file at
+-- @fpath@ on the filesystem. The
+-- 'Network.HTTP.Lucu.Resource.Resource' must be in the /Examining
+-- Request/ state before the computation. It will be in the /Done/
+-- state after the computation.
+--
+-- If you just want to place a static file on the
+-- 'Network.HTTP.Lucu.Resource.Tree.ResTree', you had better use
+-- 'staticFile' instead of this.
handleStaticFile :: FilePath -> Resource ()
handleStaticFile path
= do isFile <- liftIO $ doesFileExist path
else
foundNoEntity Nothing
-
--- |Computation @'generateETagFromFile' fpath@ generates a strong
+-- |Computation of @'generateETagFromFile' fpath@ generates a strong
-- entity tag from a file. The file doesn't necessarily have to be a
-- regular file; it may be a FIFO or a device file. The tag is made of
-- inode ID, size and modification time.
lastmod = fromEnum $ modificationTime stat
return $ strongETag $ printf "%x-%x-%x" inode size lastmod
-
+-- | @'staticDir' dir@ is a
+-- 'Network.HTTP.Lucu.Resource.Tree.ResourceDef' which maps all files
+-- in @dir@ and its subdirectories on the filesystem to the
+-- 'Network.HTTP.Lucu.Resource.Tree.ResTree'.
staticDir :: FilePath -> ResourceDef
staticDir path
= ResourceDef {
, resDelete = Nothing
}
-
+-- | Computation of @'handleStaticDir' dir@ maps all files in @dir@
+-- and its subdirectories on the filesystem to the
+-- 'Network.HTTP.Lucu.Resource.Tree.ResTree'. The
+-- 'Network.HTTP.Lucu.Resource.Resource' must be in the /Examining
+-- Request/ state before the computation. It will be in the /Done/
+-- state after the computation.
+--
+-- If you just want to place a static directory tree on the
+-- 'Network.HTTP.Lucu.Resource.Tree.ResTree', you had better use
+-- 'staticDir' instead of this.
handleStaticDir :: FilePath -> Resource ()
handleStaticDir basePath
= do extraPath <- getPathInfo