/usr/share/doc/libghc-wai-app-static-doc/html/wai-app-static.txt is in libghc-wai-app-static-doc 3.1.6.1-3build13.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | -- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | WAI application for static serving
--
-- API docs and the README are available at
-- <a>http://www.stackage.org/package/wai-app-static</a>.
@package wai-app-static
@version 3.1.6.1
module WaiAppStatic.Types
-- | An individual component of a path, or of a filepath.
--
-- This is the core type used by wai-app-static for doing lookups. It
-- provides a smart constructor to avoid the possibility of constructing
-- unsafe path segments (though <tt>unsafeToPiece</tt> can get around
-- that as necessary).
--
-- Individual file lookup backends must know how to convert from a
-- <tt>Piece</tt> to their storage system.
data Piece
-- | Smart constructor for a <tt>Piece</tt>. Won't allow unsafe components,
-- such as pieces beginning with a period or containing a slash. This
-- <i>will</i>, however, allow null pieces.
toPiece :: Text -> Maybe Piece
fromPiece :: Piece -> Text
-- | Construct a <tt>Piece</tt> without input validation.
unsafeToPiece :: Text -> Piece
-- | Request coming from a user. Corresponds to <tt>pathInfo</tt>.
type Pieces = [Piece]
-- | Call <tt>toPiece</tt> on a list.
--
-- <pre>
-- toPieces = mapM toPiece
-- </pre>
toPieces :: [Text] -> Maybe Pieces
-- | Values for the max-age component of the cache-control response header.
data MaxAge
-- | no cache-control set
NoMaxAge :: MaxAge
-- | set to the given number of seconds
MaxAgeSeconds :: Int -> MaxAge
-- | essentially infinite caching; in reality, probably one year
MaxAgeForever :: MaxAge
-- | Just the name of a folder.
type FolderName = Piece
-- | Represent contents of a single folder, which can be itself either a
-- file or a folder.
data Folder
Folder :: [Either FolderName File] -> Folder
[folderContents] :: Folder -> [Either FolderName File]
-- | Information on an individual file.
data File
File :: Integer -> (Status -> ResponseHeaders -> Response) -> Piece -> IO (Maybe ByteString) -> Maybe EpochTime -> File
-- | Size of file in bytes
[fileGetSize] :: File -> Integer
-- | How to construct a WAI response for this file. Some files are stored
-- on the filesystem and can use <tt>ResponseFile</tt>, while others are
-- stored in memory and should use <tt>ResponseBuilder</tt>.
[fileToResponse] :: File -> Status -> ResponseHeaders -> Response
-- | Last component of the filename.
[fileName] :: File -> Piece
-- | Calculate a hash of the contents of this file, such as for etag.
[fileGetHash] :: File -> IO (Maybe ByteString)
-- | Last modified time, used for both display in listings and
-- if-modified-since.
[fileGetModified] :: File -> Maybe EpochTime
-- | Result of looking up a file in some storage backend.
--
-- The lookup is either a file or folder, or does not exist.
data LookupResult
LRFile :: File -> LookupResult
LRFolder :: Folder -> LookupResult
LRNotFound :: LookupResult
-- | How to construct a directory listing page for the given request path
-- and the resulting folder.
type Listing = Pieces -> Folder -> IO Builder
-- | All of the settings available to users for tweaking wai-app-static.
--
-- Note that you should use the settings type approach for modifying
-- values. See <a>http://www.yesodweb.com/book/settings-types</a> for
-- more information.
data StaticSettings
StaticSettings :: (Pieces -> IO LookupResult) -> (File -> IO MimeType) -> [Piece] -> Maybe Listing -> MaxAge -> (Pieces -> ByteString -> ByteString) -> Bool -> Bool -> Bool -> Maybe Application -> StaticSettings
-- | Lookup a single file or folder. This is how you can control storage
-- backend (filesystem, embedded, etc) and where to lookup.
[ssLookupFile] :: StaticSettings -> Pieces -> IO LookupResult
-- | Determine the mime type of the given file. Note that this function
-- lives in <tt>IO</tt> in case you want to perform more complicated
-- mimetype analysis, such as via the <tt>file</tt> utility.
[ssGetMimeType] :: StaticSettings -> File -> IO MimeType
-- | Ordered list of filenames to be used for indices. If the user requests
-- a folder, and a file with the given name is found in that folder, that
-- file is served. This supercedes any directory listing.
[ssIndices] :: StaticSettings -> [Piece]
-- | How to perform a directory listing. Optional. Will be used when the
-- user requested a folder.
[ssListing] :: StaticSettings -> Maybe Listing
-- | Value to provide for max age in the cache-control.
[ssMaxAge] :: StaticSettings -> MaxAge
-- | Given a requested path and a new destination, construct a string that
-- will go there. Default implementation will use relative paths.
[ssMkRedirect] :: StaticSettings -> Pieces -> ByteString -> ByteString
-- | If <tt>True</tt>, send a redirect to the user when a folder is
-- requested and an index page should be displayed. When <tt>False</tt>,
-- display the content immediately.
[ssRedirectToIndex] :: StaticSettings -> Bool
-- | Prefer usage of etag caching to last-modified caching.
[ssUseHash] :: StaticSettings -> Bool
-- | Force a trailing slash at the end of directories
[ssAddTrailingSlash] :: StaticSettings -> Bool
-- | Optional <a>Application</a> to be used in case of 404 errors
--
-- Since 3.1.3
[ss404Handler] :: StaticSettings -> Maybe Application
instance GHC.Classes.Ord WaiAppStatic.Types.Piece
instance GHC.Classes.Eq WaiAppStatic.Types.Piece
instance GHC.Show.Show WaiAppStatic.Types.Piece
module WaiAppStatic.Listing
-- | Provides a default directory listing, suitable for most apps.
--
-- Code below taken from Happstack:
-- <a>http://patch-tag.com/r/mae/happstack/snapshot/current/content/pretty/happstack-server/src/Happstack/Server/FileServe/BuildingBlocks.hs</a>
defaultListing :: Listing
-- | Access files on the filesystem.
module WaiAppStatic.Storage.Filesystem
-- | How to calculate etags. Can perform filesystem reads on each call, or
-- use some caching mechanism.
type ETagLookup = FilePath -> IO (Maybe ByteString)
-- | Settings optimized for a web application. Files will have aggressive
-- caching applied and hashes calculated, and indices and listings are
-- disabled.
defaultWebAppSettings :: FilePath -> StaticSettings
-- | Settings optimized for a file server. More conservative caching will
-- be applied, and indices and listings are enabled.
defaultFileServerSettings :: FilePath -> StaticSettings
-- | Same as <tt>defaultWebAppSettings</tt>, but additionally uses a
-- specialized <tt>ETagLookup</tt> in place of the standard one. This can
-- allow you to cache your hash values, or even precompute them.
webAppSettingsWithLookup :: FilePath -> ETagLookup -> StaticSettings
module WaiAppStatic.Storage.Embedded
-- | Serve the list of path/content pairs directly from memory.
embeddedSettings :: [(FilePath, ByteString)] -> StaticSettings
-- | An Etag is used to return 304 Not Modified responses so the client
-- does not need to download resources a second time. Usually the etag is
-- built from a hash of the content. To disable Etags, you can pass the
-- empty string. This will cause the content to be redownloaded on every
-- request.
type Etag = Text
-- | Used at compile time to hold data about an entry to embed into the
-- compiled executable.
data EmbeddableEntry
EmbeddableEntry :: Text -> MimeType -> Either (Etag, ByteString) ExpQ -> EmbeddableEntry
-- | The location where this resource should be served from. The location
-- can contain forward slashes (/) to simulate directories, but must not
-- end with a forward slash.
[eLocation] :: EmbeddableEntry -> Text
-- | The mime type.
[eMimeType] :: EmbeddableEntry -> MimeType
-- | The content itself. The content can be given as a tag and bytestring,
-- in which case the content will be embedded directly into the
-- execuatble. Alternatively, the content can be given as a template
-- haskell expression returning <tt>IO (<a>Etag</a>,
-- <a>ByteString</a>)</tt> in which case this action will be executed on
-- every request to reload the content (this is useful for a debugging
-- mode).
[eContent] :: EmbeddableEntry -> Either (Etag, ByteString) ExpQ
-- | Create a <a>StaticSettings</a> at compile time that embeds resources
-- directly into the compiled executable. The embedded resources are
-- precompressed (depending on mime type) so that during runtime the
-- resource can be served very quickly.
--
-- Because of GHC Template Haskell stage restrictions, you must define
-- the entries in a different module than where you create the
-- <a>StaticSettings</a>. For example,
--
-- <pre>
-- {-# LANGUAGE TemplateHaskell, QuasiQuotes, OverloadedStrings #-}
-- module A (mkEmbedded) where
--
-- import WaiAppStatic.Storage.Embedded
-- import Crypto.Hash.MD5 (hashlazy)
-- import qualified Data.ByteString.Lazy as BL
-- import qualified Data.ByteString.Base64 as B64
-- import qualified Data.Text as T
-- import qualified Data.Text.Encoding as T
--
-- hash :: BL.ByteString -> T.Text
-- hash = T.take 8 . T.decodeUtf8 . B64.encode . hashlazy
--
-- mkEmbedded :: IO [EmbeddableEntry]
-- mkEmbedded = do
-- file <- BL.readFile "test.css"
-- let emb = EmbeddableEntry {
-- eLocation = "somedir/test.css"
-- , eMimeType = "text/css"
-- , eContent = Left (hash file, file)
-- }
--
-- let reload = EmbeddableEntry {
-- eLocation = "anotherdir/test2.txt"
-- , eMimeType = "text/plain"
-- , eContent = Right [| BL.readFile "test2.txt" >>= \c -> return (hash c, c) |]
-- }
--
-- return [emb, reload]
-- </pre>
--
-- The above <tt>mkEmbedded</tt> will be executed at compile time. It
-- loads the contents of test.css and computes the hash of test.css for
-- the etag. The content will be available at the URL somedir/test.css.
-- Internally, <tt>embedApp</tt> below will attempt to compress the
-- content at compile time. The compression will only happen if the
-- compressed content is shorter than the original and the mime type is
-- either text or javascript. If the content is compressed, at runtime
-- the precomputed compressed content will be served with the appropriate
-- HTTP header. If <tt>embedApp</tt> decides not to compress the content,
-- it will be served directly.
--
-- Secondly, <tt>mkEmbedded</tt> creates a reloadable entry. This will be
-- available at the URL anotherdir/test2.txt. Whenver a request comes in
-- for anotherdir/test2.txt, the action inside the quasiquote in eContent
-- will be executed. This will re-read the test2.txt file and recompute
-- its hash.
--
-- Finally, here is a module which uses the above action to create a
-- <a>Application</a>.
--
-- <pre>
-- {-# LANGUAGE TemplateHaskell #-}
-- module B where
--
-- import A
-- import Network.Wai (Application)
-- import Network.Wai.Application.Static (staticApp)
-- import WaiAppStatic.Storage.Embedded
-- import Network.Wai.Handler.Warp (run)
--
-- myApp :: Application
-- myApp = staticApp $(mkSettings mkEmbedded)
--
-- main :: IO ()
-- main = run 3000 myApp
-- </pre>
mkSettings :: IO [EmbeddableEntry] -> ExpQ
-- | Static file serving for WAI.
module Network.Wai.Application.Static
-- | Turn a <tt>StaticSettings</tt> into a WAI application.
staticApp :: StaticSettings -> Application
-- | Settings optimized for a web application. Files will have aggressive
-- caching applied and hashes calculated, and indices and listings are
-- disabled.
defaultWebAppSettings :: FilePath -> StaticSettings
-- | Same as <tt>defaultWebAppSettings</tt>, but additionally uses a
-- specialized <tt>ETagLookup</tt> in place of the standard one. This can
-- allow you to cache your hash values, or even precompute them.
webAppSettingsWithLookup :: FilePath -> ETagLookup -> StaticSettings
-- | Settings optimized for a file server. More conservative caching will
-- be applied, and indices and listings are enabled.
defaultFileServerSettings :: FilePath -> StaticSettings
-- | Serve the list of path/content pairs directly from memory.
embeddedSettings :: [(FilePath, ByteString)] -> StaticSettings
-- | All of the settings available to users for tweaking wai-app-static.
--
-- Note that you should use the settings type approach for modifying
-- values. See <a>http://www.yesodweb.com/book/settings-types</a> for
-- more information.
data StaticSettings
-- | Lookup a single file or folder. This is how you can control storage
-- backend (filesystem, embedded, etc) and where to lookup.
ssLookupFile :: StaticSettings -> Pieces -> IO LookupResult
-- | Given a requested path and a new destination, construct a string that
-- will go there. Default implementation will use relative paths.
ssMkRedirect :: StaticSettings -> Pieces -> ByteString -> ByteString
-- | Determine the mime type of the given file. Note that this function
-- lives in <tt>IO</tt> in case you want to perform more complicated
-- mimetype analysis, such as via the <tt>file</tt> utility.
ssGetMimeType :: StaticSettings -> File -> IO MimeType
-- | How to perform a directory listing. Optional. Will be used when the
-- user requested a folder.
ssListing :: StaticSettings -> Maybe Listing
-- | Ordered list of filenames to be used for indices. If the user requests
-- a folder, and a file with the given name is found in that folder, that
-- file is served. This supercedes any directory listing.
ssIndices :: StaticSettings -> [Piece]
-- | Value to provide for max age in the cache-control.
ssMaxAge :: StaticSettings -> MaxAge
-- | If <tt>True</tt>, send a redirect to the user when a folder is
-- requested and an index page should be displayed. When <tt>False</tt>,
-- display the content immediately.
ssRedirectToIndex :: StaticSettings -> Bool
-- | Force a trailing slash at the end of directories
ssAddTrailingSlash :: StaticSettings -> Bool
-- | Optional <a>Application</a> to be used in case of 404 errors
--
-- Since 3.1.3
ss404Handler :: StaticSettings -> Maybe Application
-- | Command line version of wai-app-static, used for the warp-static
-- server.
module WaiAppStatic.CmdLine
-- | Run with the given middleware and parsing options from the command
-- line.
--
-- Since 2.0.1
runCommandLine :: (Args -> Middleware) -> IO ()
data Args
Args :: FilePath -> [FilePath] -> Int -> Bool -> Bool -> Bool -> [(String, String)] -> String -> Args
[docroot] :: Args -> FilePath
[index] :: Args -> [FilePath]
[port] :: Args -> Int
[noindex] :: Args -> Bool
[quiet] :: Args -> Bool
[verbose] :: Args -> Bool
[mime] :: Args -> [(String, String)]
[host] :: Args -> String
|