Middleware class

A process performed on a Request before a Handler (a RequestMiddleware) and/or on a Response after a Handler (a ResponseMiddleware).

A Handler can also be provided in case of an error in the Middleware execution.

Middleware is added to a Request/Response Pipeline and can be synchronous where runAsync is false or asynchronous where runAsync is true. Middleware can be forced to run when useAlways is set to true; this is helpful for Middleware such as loggers, which should always run regardles of the Request/Response status.

Synchronous Middleware are not guaranteed to run if a prior Middleware aborts the Request/Response and useAlways is false. Asynchronous Middleware are not guaranteed to run if a sibling asynchronous Middleware finishes first and aborts the Request/Response. Asynchronous Middleware may complete in any order so they should be used carefully; generally not to modify the Request/Response if other asynchronous Middleware depend on the modification or to spawn related but independent processes such as storing a request count to a database or retrieving multiple services a handler might depend on.

Constructors

Middleware({RequestMiddleware onRequest, ResponseMiddleware onResponse, Handler error, bool runAsync: false, bool useAlways: false})
Each Middleware is provided an optional RequestMiddleware, ResponseMiddleware, and error Handler. Additional parameters runAsync and useAlways determine how the Middleware will be applied to the Pipeline.

Properties

errorHandler Handler
read-only
hashCode int
The hash code for this object. [...]
read-only, inherited
requestMiddleware RequestMiddleware
read-only
responseMiddleware ResponseMiddleware
read-only
runAsync bool
final
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
useAlways bool
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() String
Returns a string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited