Skip to content

Improve middleware composition #7

@danneu

Description

@danneu

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions