middlewares library

Classes

CompressionOptions
LimitedHttpRequestWrapper
MiddlewareRef
Convenience factory for constructing middleware references.

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
conditionalRequests({EtagResolver? etag, LastModifiedResolver? lastModified}) Middleware
Middleware that evaluates HTTP conditional request headers and short-circuits responses with 304 (Not Modified) or 412 (Precondition Failed) where appropriate.
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.
localizationMiddleware(LocaleManager manager) Middleware
Creates middleware that runs the LocaleManager before downstream handlers.
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()
EtagResolver = FutureOr<String?> Function(EngineContext ctx)
LastModifiedResolver = FutureOr<DateTime?> Function(EngineContext ctx)
Middleware = FutureOr<Response> Function(EngineContext ctx, Next next)
Middleware: may short-circuit by returning a Response, or call next().
Next = FutureOr<Response> Function()
Next function for middleware composition, returns a Response when called.
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.