Ogeon / rustful

[OUTDATED] A light HTTP framework for Rust
https://docs.rs/rustful
Apache License 2.0
862 stars 51 forks source link

Are there Middleware achievement plan ? #93

Closed inxi-pc closed 8 years ago

inxi-pc commented 8 years ago

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.

Ogeon commented 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...

inxi-pc commented 8 years ago

Hi, Ogeon, Thanks very much. I think function auth_or_fail is also can solve my problem.

Ogeon commented 8 years ago

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.