HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulewai-middleware-static-0.9.4Haskell2010

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.

Contents
  1. Middlewares
  2. Options
  3. Cache Control
  4. Policies
  5. Utilities
  6. MIME types
Synopsis

Middlewares

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

Cache Control

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

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.4 · Network.Wai.Middleware.Static

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

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

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

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

MIME types