How to make "middleware" filter for warp web server?

For example, i want to have an ability to require user to be authorized in some paths, something like this:

let routes = warp::path("api").and(
    warp::path::end().map(api_index)
    .or(
        warp::path("item").and(
            warp::path!(u64).map(item_show)
            .or(warp::path!("add" / u64 / String / String).and(auth()).map(item_add))
            .or(warp::path!("delete" / u64).and(auth()).map(item_delete))
        )
    )
    .or(
        warp::path("user").and(auth()).and(
            warp::path!("update_profile" / String / String).map(user_update_profile)
            .or(warp::path!("set_pass" / String).map(user_set_pass))
        )
    )
)

where i suppose fn auth() returning Filter, which can reject or accept (may by with additional extracted appropriate User struct), depending on values of some headers

fn auth() -> impl Filter<Extract = (User, ), Error = Rejection> + Copy {
    warp::header("Auth-User").and(
        warp::header("Auth-Timestamp")
    ).and(
        warp::header("Auth-Hash")
    ).and(
        warp::query::raw()
    ).map(|auth_user, auth_timestamp, auth_hash, raw_query| -> ??? {
        let user = User::find(auth_user)?;
        ...
        some authorization logic
        ...
        user
    })
}

but i don't understand how to conditionally make either success or reject depending on authorization logic

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.