Processing Flow
Service first converts the request into Salvo's Response, then enters the routing matching phase.
Routing Matching Phase
Routing matching runs filters in the order they were added, proceeding from outer to inner and top to bottom. If any filter fails, the match is considered unsuccessful.
During the matching process, the request's path information is consumed progressively. Once a path filter matches successfully, it consumes the matched portion of the path. When all path segments are consumed, and no filter fails along the matching chain, and the last Router on the current chain has a goal Handler, the match is successful, and the matching phase ends. All Handlers collected from the matching chain proceed to the execution phase.
If the path is not fully consumed, no errors occur along the chain, but there are no further child routes to continue matching, the current chain is considered a match failure, and the process moves to the next route for matching.
If all routes are matched without success, the process enters the error-catching phase.
Handler Execution Phase
The Handlers collected during the matching phase are executed sequentially. During execution, preceding middleware can call ctrl::call_next() to allow subsequent middleware to execute first before running its own logic. If an error status code or a redirect occurs during execution, subsequent Handlers will not be executed. If the status code indicates an error and the Response's Body is unset or is ResBody::Error, the process enters the error-catching phase; otherwise, it skips the catching phase.
Error-Catching Phase
Catcher is a type used to handle errors and can also include middleware (hoops). Errors pass through all Handlers within the Catcher sequentially. If a Handler has already handled the error and does not want subsequent Handlers to continue, it can skip the rest using ctrl.skip_rest(), directly ending the catching phase.
Catcher must include at least one Handler as the default error handler. The default is DefaultGoal, but you can fully customize your own Handler as the default error-handling implementation. It displays error information in the format requested by the content-type header, supporting json, xml, text, and html formats. DefaultGoal also provides display settings; for example, by default, it displays Salvo-related links when showing HTML format. You can call DefaultGoal::footer or DefaultGoal::with_footer to set a custom footer as desired.
Service converts Salvo's Response into Hyper's Response type, which is ultimately returned to clients such as browsers.
Salvo Request Lifecycle
This is a visual representation and explanation of the HTTP request lifecycle in the Salvo web framework.