Gets a path from the Request using rqPathInfo and makes sure it is
safe to use for opening files. A path is safe if it is a relative path
and has no ".." elements to escape the intended directory structure.
Example:
ghci> :set -XOverloadedStrings
ghci> import qualified Data.Map as M
ghci> import qualified Snap.Test as T
ghci> import qualified Data.ByteString.Char8 as B8
ghci> T.runHandler (T.get "/foo/bar" M.empty) (getSafePath >>= writeBS . B8.pack)
HTTP/1.1 200 OK
server: Snap/test
date: Fri, 08 Aug 2014 16:13:20 GMT
foo/bar
ghci> T.runHandler (T.get "/foo/../bar" M.empty) (getSafePath >>= writeBS . B8.pack)
HTTP/1.1 404 Not Found
...
A very simple configuration for directory serving. This configuration
uses built-in MIME types from defaultMimeTypes, and has no index files,
index generator, dynamic file handlers, or preServeHook.
A reasonable default configuration for directory serving. This
configuration uses built-in MIME types from defaultMimeTypes, serves
common index files index.html and index.htm, but does not autogenerate
directory indexes, nor have any dynamic file handlers. The preServeHook
will not do anything.
A more elaborate configuration for file serving. This configuration
uses built-in MIME types from defaultMimeTypes, serves common index files
index.html and index.htm, and autogenerates directory indexes with a
Snap-like feel. It still has no dynamic file handlers, nor preServeHook,
which should be added as needed.
Files recognized as indexes include index.html, index.htm,
default.html, default.htm, home.html
Example of how the autogenerated directory index looks like:
An automatic index generator, which is fairly small and does not rely on
any external files (which may not be there depending on external request
routing).
A MimeMap is passed in to display the types of files in the directory
listing based on their extension. Preferably, this is the same as the map
in the DirectoryConfig
The styles parameter allows you to apply styles to the directory listing.
The listing itself consists of a table, containing a header row using
th elements, and one row per file using td elements, so styles for those
pieces may be attached to the appropriate tags.
Serves static files from a directory. Configuration options are
passed in a DirectoryConfig that captures various choices about desired
behavior. The relative path given in rqPathInfo is searched for a
requested file, and the file is served with the appropriate mime type if it
is found. Absolute paths and ".." are prohibited to prevent files from
being served from outside the sandbox.
Serves a single file specified by a full or relative path. If the file
does not exist, throws an exception (not that it does not pass to the
next handler). The path restrictions on serveDirectory don't apply to
this function since the path is not being supplied by the user.