1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Middleware trait: IMiddleware.
use crateResult;
use crateIHttpContext;
use ControlFlow;
/// Where a user middleware runs relative to the framework's built-in stages.
///
/// The default for [`HostBuilder::use_middleware`] is [`MiddlewareSlot::AfterAuth`],
/// so a middleware that reads the authenticated principal (`ctx.claims()`)
/// actually sees it: authentication runs before the slot. Use
/// [`MiddlewareSlot::BeforeCors`] only when the middleware must observe requests
/// that CORS would otherwise short-circuit (e.g. preflight accounting), and
/// [`MiddlewareSlot::AfterSpa`] for post-static-file hooks.
///
/// [`HostBuilder::use_middleware`]: https://docs.rs/rust-webx-host
/// Middleware component in the HTTP request pipeline.
///
/// Middlewares are called in registration order. Each middleware can:
/// - Inspect/modify the request before passing through
/// - Short-circuit by returning `ControlFlow::Break(())`
/// - The pipeline continues to the next middleware on `ControlFlow::Continue(())`
///
/// On short-circuit, remaining middleware and the final handler are skipped,
/// but `after` hooks on already-executed middleware still run in reverse order.
///
/// `after` also runs when a middleware's `invoke` or the handler returns an
/// error: the pipeline unwinds the middleware that already entered, so
/// metrics, tracing and cleanup never miss a failed request.
///
/// Analogous to ASP.NET Core's IMiddleware.