Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve middleware composition #7

Open
danneu opened this issue Mar 26, 2018 · 0 comments
Open

Improve middleware composition #7

danneu opened this issue Mar 26, 2018 · 0 comments

Comments

@danneu
Copy link
Owner

danneu commented Mar 26, 2018

My previous iteration had a cuter solution: https://github.com/danneu/hunk-prev/blob/master/src/lib.rs#L70-L81

let factory = move |peer: Option<SocketAddr>| {
    // Request travels from bottom to top,
    // Response travels from top to bottom.
    pipe!(
        Root::new(pool, &config.server),
        (Browse::new[&config.browse, root.as_path()]),
        (Cors::new[&config.cors]),
        (Compress::new[pool, &config.gzip]),
        (Log::new[peer, &config.log]),
        (Gate::new[])
    )
};

When I rewrote the server, I found it easier to figure out lifetimes when the services manually called another_service.call(req) instead of holding the next service in their struct. But I have a branch that figured it out again.

Also, ideally unused middleware simply wouldn't appear in the chain instead of no-op'ing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant