HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulewai-middleware-static-0.9.2Haskell2010

Network.Wai.Middleware.Static

Serve static files, subject to a policy that can filter or modify incoming URIs. The flow is:

incoming request URI ==> policies ==> exists? ==> respond

If any of the polices fail, or the file doesn't exist, then the middleware gives up and calls the inner application. If the file is found, the middleware chooses a content type based on the file extension and returns the file contents as the response.

  • 5 types
  • 27 values

Middlewares

9 declarations
valuestatic :: Middleware
#

Serve static files out of the application root (current directory). If file is found, it is streamed to the client and no further middleware is run. Disables caching.

Note: for security reasons, this uses the noDots and isNotAbsolute policy by default.

Options

4 declarations

Cache Control

4 declarations
datadata CachingStrategy
#

A cache strategy which should be used to serve content matching a policy. Meta information is cached for a maxium of 100 seconds before being recomputed.

Constructors

Policies

13 declarations
newtypenewtype Policy
#

Take an incoming URI and optionally modify or filter it. The result will be treated as a filepath.

Instances2Semigroup, Monoid
  • Semigroup PolicyDefined in wai-middleware-static-0.9.2 · Network.Wai.Middleware.Static

    Note: (<>) == >-> (policy sequencing)

  • Monoid PolicyDefined in wai-middleware-static-0.9.2 · Network.Wai.Middleware.Static

    Note: mempty == policy Just (the always accepting policy) mappend == >-> (policy sequencing)

value(<|>) :: Policy -> Policy -> Policy
#

Choose between two policies. If the first fails, run the second.

valueaddBase :: String -> Policy
#

Add a base path to the URI

staticPolicy (addBase "/home/user/files")

GET "foo/bar" looks for "/home/user/files/foo/bar"

valueaddSlash :: Policy
#

Add an initial slash to to the URI, if not already present.

staticPolicy addSlash

GET "foo/bar" looks for "/foo/bar"

valueonly :: [(String, String)] -> Policy
#

Use URI as the key to an association list, rejecting those not found. The policy result is the matching value.

staticPolicy (only [("foo/bar", "/home/user/files/bar")])

GET "foo/bar" looks for "/home/user/files/bar" GET "baz/bar" doesn't match anything

Utilities

1 declaration

MIME types

1 declaration