wai-extra-3.1.17: Provides some basic WAI handlers and middleware.

Copyright | Michael Snoyman
License | BSD3
Maintainer | Michael Snoyman <michael@snoyman.com>
Stability | Unstable
Portability | portable
Safe Haskell | None
Language | Haskell2010

Network.Wai.Middleware.Select

Contents

- Middleware selection
- Helpers

Description

Dynamically choose between Middlewares

It's useful when you want some `Middleware`s applied selectively.

Example: do not log health check calls:

    import Network.Wai
    import Network.Wai.Middleware.HealthCheckEndpoint
    import Network.Wai.Middleware.RequestLogger

    app' :: Application
    app' =
      selectMiddleware (selectMiddlewareExceptRawPathInfo "/_healthz" logStdout)
        $ healthCheck app

Since: 3.1.10

Synopsis

- newtype MiddlewareSelection = MiddlewareSelection {
  - applySelectedMiddleware :: Request -> Maybe Middleware
  }
- selectMiddleware :: MiddlewareSelection -> Middleware
- selectMiddlewareOn :: (Request -> Bool) -> Middleware -> MiddlewareSelection
- selectMiddlewareOnRawPathInfo :: ByteString -> Middleware -> MiddlewareSelection
- selectMiddlewareExceptRawPathInfo :: ByteString -> Middleware -> MiddlewareSelection
- passthroughMiddleware :: Middleware

# Middleware selection

newtype MiddlewareSelection #

Relevant Middleware for a given `Request`.

Constructors

MiddlewareSelection |
Fields applySelectedMiddleware :: Request -> Maybe Middleware

#### Instances

Instances details

Monoid MiddlewareSelection # |
Instance details Defined in Network.Wai.Middleware.Select Methods mempty :: MiddlewareSelection # mappend :: MiddlewareSelection -> MiddlewareSelection -> MiddlewareSelection # mconcat :: [MiddlewareSelection] -> MiddlewareSelection #
Semigroup MiddlewareSelection # |
Instance details Defined in Network.Wai.Middleware.Select Methods (<>) :: MiddlewareSelection -> MiddlewareSelection -> MiddlewareSelection # sconcat :: NonEmpty MiddlewareSelection -> MiddlewareSelection # stimes :: Integral b => b -> MiddlewareSelection -> MiddlewareSelection #

selectMiddleware :: MiddlewareSelection -> Middleware #

Create the `Middleware` dynamically applying `MiddlewareSelection`.

# Helpers

selectMiddlewareOn :: (Request -> Bool) -> Middleware -> MiddlewareSelection #

Use the `Middleware` when the predicate holds.

selectMiddlewareOnRawPathInfo :: ByteString -> Middleware -> MiddlewareSelection #

Use the `Middleware` for the given `rawPathInfo`.

selectMiddlewareExceptRawPathInfo :: ByteString -> Middleware -> MiddlewareSelection #

Use the `Middleware` for all `rawPathInfo` except then given one.

passthroughMiddleware :: Middleware #