| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
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
) runs with the captured path segments and the incoming request.Captures->Application - If the path matches but the HTTP method does not, a
405 Method Not Allowedresponse is returned with anAllowheader listing the supported methods. - If neither the path nor a splat matches, the request is handed to the
fallbackapplication — 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).