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

Copyright | Michael Snoyman
License | BSD3
Maintainer | Michael Snoyman <michael@snoyman.com>
Stability | Unstable
Portability | portable
Safe Haskell | Safe-Inferred
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 Source #

Relevant Middleware for a given `Request`.

Constructors

MiddlewareSelection |

Fields

- applySelectedMiddleware :: Request -> Maybe Middleware

#### Instances

Instances details

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

selectMiddleware :: MiddlewareSelection -> Middleware Source #

Create the `Middleware` dynamically applying `MiddlewareSelection`.

# Helpers

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

Use the `Middleware` when the predicate holds.

selectMiddlewareOnRawPathInfo :: ByteString -> Middleware -> MiddlewareSelection Source #

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

selectMiddlewareExceptRawPathInfo :: ByteString -> Middleware -> MiddlewareSelection Source #

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

passthroughMiddleware :: Middleware Source #