happstack-server-0.4.1: Web related tools and services.Source codeContentsIndex
Happstack.Server.HTTP.FileServe
Contents
Content-Type / Mime-Type
Low-Level
High-Level
Serving a single file
Serving files from a directory
Other
Description
File Serving functions
Synopsis
type MimeMap = Map String String
mimeTypes :: MimeMap
asContentType :: Monad m => String -> FilePath -> m String
guessContentType :: MimeMap -> FilePath -> Maybe String
guessContentTypeM :: Monad m => MimeMap -> FilePath -> m String
sendFileResponse :: String -> FilePath -> Maybe (CalendarTime, Request) -> Integer -> Integer -> Response
lazyByteStringResponse :: String -> ByteString -> Maybe (CalendarTime, Request) -> Integer -> Integer -> Response
strictByteStringResponse :: String -> ByteString -> Maybe (CalendarTime, Request) -> Integer -> Integer -> Response
filePathSendFile :: (ServerMonad m, MonadIO m) => String -> FilePath -> m Response
filePathLazy :: (ServerMonad m, MonadIO m) => String -> FilePath -> m Response
filePathStrict :: (ServerMonad m, MonadIO m) => String -> FilePath -> m Response
serveFile :: (ServerMonad m, FilterMonad Response m, MonadIO m) => (FilePath -> m String) -> FilePath -> m Response
serveFileUsing :: (ServerMonad m, FilterMonad Response m, MonadIO m) => (String -> FilePath -> m Response) -> (FilePath -> m String) -> FilePath -> m Response
fileServe' :: (WebMonad Response m, ServerMonad m, FilterMonad Response m, MonadIO m) => (String -> FilePath -> m Response) -> (FilePath -> m String) -> [FilePath] -> FilePath -> m Response
fileServe :: (WebMonad Response m, ServerMonad m, FilterMonad Response m, MonadIO m) => [FilePath] -> FilePath -> m Response
fileServeLazy :: (WebMonad Response m, ServerMonad m, FilterMonad Response m, MonadIO m) => [FilePath] -> FilePath -> m Response
fileServeStrict :: (WebMonad Response m, ServerMonad m, FilterMonad Response m, MonadIO m) => [FilePath] -> FilePath -> m Response
blockDotFiles :: (Request -> IO Response) -> Request -> IO Response
defaultIxFiles :: [String]
doIndex :: (ServerMonad m, FilterMonad Response m, MonadIO m) => [String] -> MimeMap -> String -> m Response
doIndex' :: (ServerMonad m, FilterMonad Response m, MonadIO m) => (String -> FilePath -> m Response) -> (FilePath -> m String) -> [String] -> String -> m Response
doIndexLazy :: (ServerMonad m, FilterMonad Response m, MonadIO m) => [String] -> MimeMap -> String -> m Response
doIndexStrict :: (ServerMonad m, FilterMonad Response m, MonadIO m) => [String] -> MimeMap -> String -> m Response
errorwrapper :: (MonadIO m, MonadPlus m, FilterMonad Response m) => String -> String -> m Response
isDot :: String -> Bool
Content-Type / Mime-Type
type MimeMap = Map String StringSource
mimeTypes :: MimeMapSource
Ready collection of common mime types. Except for the first two entries, the mappings come from an Ubuntu 8.04 etcmime.types file.
asContentType :: Monad m => String -> FilePath -> m StringSource
guessContentType :: MimeMap -> FilePath -> Maybe StringSource
guessContentTypeM :: Monad m => MimeMap -> FilePath -> m StringSource
Low-Level
sendFileResponseSource
:: Stringcontent-type string
-> FilePathfile path for content to send
-> Maybe (CalendarTime, Request)mod-time for the handle (MUST NOT be later than server's time of message origination), incoming request (used to check for if-modified-since header)
-> Integeroffset into Handle
-> Integernumber of bytes to send
-> Response
Use sendFile to send the contents of a Handle
lazyByteStringResponseSource
:: Stringcontent-type string (e.g. "text/plain; charset=utf-8")
-> ByteStringlazy bytestring content to send
-> Maybe (CalendarTime, Request)mod-time for the bytestring, incoming request (used to check for if-modified-since header)
-> Integeroffset into the bytestring
-> Integernumber of bytes to send (offset + count must be less than or equal to the length of the bytestring)
-> Response
Send the contents of a Lazy ByteString
strictByteStringResponseSource
:: Stringcontent-type string (e.g. "text/plain; charset=utf-8")
-> ByteStringlazy bytestring content to send
-> Maybe (CalendarTime, Request)mod-time for the bytestring, incoming request (used to check for if-modified-since header)
-> Integeroffset into the bytestring
-> Integernumber of bytes to send (offset + count must be less than or equal to the length of the bytestring)
-> Response
Send the contents of a Lazy ByteString
filePathSendFileSource
:: (ServerMonad m, MonadIO m)
=> Stringcontent-type string
-> FilePathpath to file on disk
-> m Response

Send the specified file with the specified mime-type using sendFile()

NOTE: assumes file exists and is readable by the server. See serveFileUsing.

WARNING: No security checks are performed.

filePathLazySource
:: (ServerMonad m, MonadIO m)
=> Stringcontent-type string
-> FilePathpath to file on disk
-> m Response

Send the specified file with the specified mime-type using Lazy ByteStrings

NOTE: assumes file exists and is readable by the server. See serveFileUsing.

WARNING: No security checks are performed.

filePathStrictSource
:: (ServerMonad m, MonadIO m)
=> Stringcontent-type string
-> FilePathpath to file on disk
-> m Response

Send the specified file with the specified mime-type using Lazy ByteStrings

NOTE: assumes file exists and is readable by the server. See serveFileUsing.

WARNING: No security checks are performed.

High-Level
Serving a single file
serveFile :: (ServerMonad m, FilterMonad Response m, MonadIO m) => (FilePath -> m String) -> FilePath -> m ResponseSource
Alias for serveFileUsing filePathSendFile
serveFileUsingSource
:: (ServerMonad m, FilterMonad Response m, MonadIO m)
=> String -> FilePath -> m Responsetypically filePathSendFile, filePathLazy, or filePathStrict
-> FilePath -> m Stringfunction for determining content-type of file. Typically asContentType or guessContentTypeM
-> FilePathpath to the file to serve
-> m Response

Serve a single, specified file.

example 1:

Serve using sendfile() and the specified content-type

 serveFileUsing filePathSendFile (asContentType "image/jpeg") "/srv/data/image.jpg"

example 2:

Serve using a lazy ByteString and the guess the content-type from the extension

 serveFileUsing filePathLazy (guessContentTypeM mimeTypes) "/srv/data/image.jpg"

WARNING: No security checks are performed.

Serving files from a directory
fileServe'Source
:: (WebMonad Response m, ServerMonad m, FilterMonad Response m, MonadIO m)
=> String -> FilePath -> m Responsefunction which takes a content-type and filepath and generates a response (typically filePathSendFile, filePathLazy, or filePathStrict)
-> FilePath -> m Stringfunction which returns the mime-type for FilePath
-> [FilePath]index files if the path is a directory
-> FilePathfile/directory to serve
-> m Response

Serve files from a directory and it's subdirectories (parameterizable version)

Parameterize this function to create functions like, fileServe, fileServeLazy, and fileServeStrict

You supply:

1. a low-level function which takes a content-type and FilePath and generates a Response 2. a function which determines the content-type from the FilePath 3. a list of all the default index files

NOTE: unlike fileServe, there are no index files by default. See defaultIxFiles.

fileServeSource
:: (WebMonad Response m, ServerMonad m, FilterMonad Response m, MonadIO m)
=> [FilePath]index files if the path is a directory
-> FilePathfile/directory to serve
-> m Response
Serve files from a directory and it's subdirectories (sendFile version). Should perform much better than its predecessors.
fileServeLazySource
:: (WebMonad Response m, ServerMonad m, FilterMonad Response m, MonadIO m)
=> [FilePath]index files if the path is a directory
-> FilePathfile/directory to serve
-> m Response

Serve files from a directory and it's subdirectories (lazy ByteString version).

May leak file handles.

fileServeStrictSource
:: (WebMonad Response m, ServerMonad m, FilterMonad Response m, MonadIO m)
=> [FilePath]index files if the path is a directory
-> FilePathfile/directory to serve
-> m Response
Serve files from a directory and it's subdirectories (strict ByteString version).
Other
blockDotFiles :: (Request -> IO Response) -> Request -> IO ResponseSource
Prevents files of the form '.foo' or 'bar/.foo' from being served
defaultIxFiles :: [String]Source
doIndex :: (ServerMonad m, FilterMonad Response m, MonadIO m) => [String] -> MimeMap -> String -> m ResponseSource
doIndex' :: (ServerMonad m, FilterMonad Response m, MonadIO m) => (String -> FilePath -> m Response) -> (FilePath -> m String) -> [String] -> String -> m ResponseSource
doIndexLazy :: (ServerMonad m, FilterMonad Response m, MonadIO m) => [String] -> MimeMap -> String -> m ResponseSource
doIndexStrict :: (ServerMonad m, FilterMonad Response m, MonadIO m) => [String] -> MimeMap -> String -> m ResponseSource
errorwrapper :: (MonadIO m, MonadPlus m, FilterMonad Response m) => String -> String -> m ResponseSource
isDot :: String -> BoolSource
Returns True if the given String either starts with a . or is of the form foo/.bar, e.g. the typical *nix convention for hidden files.
Produced by Haddock version 2.6.1