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
Rocket::attach() method on the application's
Rocket instance and
passing in the appropriate
Fairing. For instance, to attach fairings
res_fairing to a new Rocket instance, you might
let rocket = rocket::ignite() .attach(req_fairing) .attach(res_fairing);
Once a fairing is attached, Rocket will execute it at the appropriate 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.
A ad-hoc fairing that can be created from a function or closure.
Information about a
A bitset representing the kinds of callbacks a
Trait implemented by fairings: Rocket's structured middleware.