Closed inxi-pc closed 8 years ago
Hi! Thank your for your suggestion. Rustful is currently not middleware oriented and there are currently no concrete plans for it. There is, however, support for "filters", which works like a subgroup of middleware, but they have been neglected for a while and their design isn't necessarily great.
The reason why it hasn't yet been made middleware oriented is that the same functionality often can be achieved using good old function calls. Something like:
fn my_handler(context: Context, response: Response) {
let (context, response) = if let Some(res) = auth_or_fail(context, response) {
res
} else {
return;
}
//...
}
This can be made less verbose with a try!
like macro:
fn my_handler(context: Context, response: Response) {
let (context, response) = expect!(auth_or_fail(context, response));
//...
}
This doesn't mean that the door is closed for middleware. Just that there hasn't been any work on it. Thinking about it, making handlers return Option<(Context, Response)>
would make them quite easy to stack... hmm...
Hi, Ogeon, Thanks very much. I think function auth_or_fail is also can solve my problem.
Alright. Note that auth_or_fail
is purely hypothetical and you may need something more advanced. Feel free to reopen if you want to go any further with this.
This is a nice framework, i want to use in our web project, but after my overview, i dont find Middleware function achievement. I think this is useful in authorization webservice. I dont know if you have this plan?
:) Thanks.