ihp-router-1.0.0: Trie-based routing with a Yesod-style DSL for WAI
Safe HaskellNone
LanguageGHC2021

IHP.Router.Middleware

Description

routeTrieMiddleware wraps a pre-built RouteTrie as a standard WAI Middleware. On a match it invokes the trie-selected handler with the captured path segments; on a method mismatch it returns 405 Method Not Allowed with an Allow header; on no match at all it delegates to the fallback Application passed in by middleware composition.

Synopsis

Documentation

routeTrieMiddleware :: RouteTrie -> Middleware Source #

Wrap a RouteTrie as a WAI Middleware.

Semantics:

  • If the trie matches, the matched handler (a Captures -> Application) runs with the captured path segments and the incoming request.
  • If the path matches but the HTTP method does not, a 405 Method Not Allowed response is returned with an Allow header listing the supported methods.
  • If neither the path nor a splat matches, the request is handed to the fallback application — which is the standard WAI behaviour when a middleware declines a request.

The middleware is pure with respect to the trie: construction happens at application startup, lookup on every request.

methodNotAllowedResponse :: [StdMethod] -> Response Source #

Build a 405 Method Not Allowed response with a properly-formatted Allow header (comma-separated, per RFC 7231 §7.4.1).