middleware library

Built-in middleware shipped with Routed.

Import this file to wire middleware individually instead of pulling the entire framework barrel.

Constants

compressionSkipAttribute → const String

Functions

applyCorsHeaders(HttpHeaders requestHeaders, String requestMethod, HttpHeaders responseHeaders, CorsConfig config) bool
basicAuth(AuthAccounts accounts, {String realm = 'Restricted Area'}) Middleware
Middleware function for basic authentication.
compressionMiddleware(CompressionOptionsResolver resolver) Middleware
corsMiddleware() Middleware
csrfMiddleware() Middleware
disableCompression(EngineContext ctx) → void
Marks the current request so the compression middleware skips encoding.
enableCompression(EngineContext ctx) → void
Clears compression skip flags for the current request.
generateCsrfToken() String
isAlgorithmSupported(CompressionAlgorithm algorithm) bool
limitRequestBody(int maxBytes) Middleware
Middleware that rejects requests whose body is larger than maxBytes.
parseCompressionAlgorithm(String value) CompressionAlgorithm?
rateLimitMiddleware(RateLimitService service) Middleware
recoveryMiddleware({RecoveryHandler? handler}) Middleware
Middleware that provides error recovery functionality.
requestSizeLimitMiddleware() Middleware
requestTrackerMiddleware() Middleware
Middleware function to track the duration of each request.
securityHeadersMiddleware() Middleware
timeoutMiddleware(Duration duration) Middleware
Middleware that enforces a timeout on the request processing chain.

Typedefs

AuthAccounts = Map<String, String>
A typedef for a map that holds authentication accounts. The key is the username and the value is the password.
CompressionOptionsResolver = CompressionOptions Function()
RecoveryHandler = void Function(EngineContext ctx, Object error, StackTrace stack)
A type definition for the recovery handler function. This function is called when an error occurs during the execution of a middleware.