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 useParallel is false or asynchronous where useParallel is
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.
Middleware are executed in the following order:
- Synchronous RequestMiddleware in the order they are added to the Router
- Asynchronous RequestMiddleware asynchronously until they are all completed
- The request Handler which initiates the response
- Asynchronous ResponseMiddleware asynchronously until they are all completed
- Synchronous ResponseMiddleware in the reverse order they are added to the Router
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.
ResponseMiddleware post, Handler error, bool useParallel: false, bool useAlways: false} )
Each Middleware is provided an optional RequestMiddleware, ResponseMiddleware,
and error Handler. Additional parameters
useAlwaysdetermine how the Middleware will be applied to the Pipeline.
- errorProcess → Handler
- postProcess → ResponseMiddleware
- preProcess → RequestMiddleware
- useAlways → bool
- useParallel → bool
- hashCode → int
The hash code for this object. [...]
- runtimeType → Type
A representation of the runtime type of the object.