Fairings: callbacks at attach, launch, request, and response time.
Fairings allow for structured interposition at various points in the application lifetime. Fairings can be seen as a restricted form of "middleware". A fairing is an arbitrary structure with methods representing callbacks that Rocket will run at requested points in a program. You can use fairings to rewrite or record information about requests and responses, or to perform an action once a Rocket application has launched.
You must inform Rocket about fairings that you wish to be active by calling
attach method on the
Rocket instance and passing in the
Fairing. For instance, to attach fairings named
res_fairing to a new Rocket instance, you might write:
let rocket = rocket::ignite() .attach(req_fairing) .attach(res_fairing);
Once a fairing is attached, Rocket will execute it at the appropiate time,
which varies depending on the fairing implementation. See the
trait documentation for more information on the dispatching of fairing
Fairings are executed in the order in which they are attached: the first
attached fairing has its callbacks executed before all others. Because
fairing callbacks may not be commutative, the order in which fairings are
attached may be significant. Because of this, it is important to communicate
to the user every consequence of a fairing.
Fairing should take care to act locally so that the actions
Fairings are not jeopardized. For instance, unless it is made
abundantly clear, a fairing should not rewrite every request.
Information about a
A bitset representing the kinds of callbacks a
A ad-hoc fairing that can be created from a function or closure.
Trait implemented by fairings: Rocket's structured middleware.