I have this right now:
warp::header::<String>("accept-encoding").or(warp::any().map(|| String::new())).unify()
Is there a way to extract an optional header like:
warp::header::<Option<String>>("accept-encoding")
I think adding a general optional method to the Filter trait may be a nice addition. It'd be sort of like Result::ok()...
@seanmonstar First of all, I really really like your work.
I have a similar issue.
warp::any().and(warp::header::<String>("authorization")
.map(|token: String| { // ...something to do with token }
This filter composition rejects all the request without authorization in header. But, I'd like to modify it with optional condition if request doesn't contain a authorization in header. How can I achieve it?
I'm sorry I'm very new to Rust, can you show me a example code for this?
@mattdamon108 That'd just use an or filter:
let default_auth = warp::any().map(|| {
// something default
});
let auth = warp::header("authorization")
.map(|token: String| {
// something with token
})
.or(default_auth)
.unify();
@seanmonstar It works like charm! Thank you for your help!
Most helpful comment
@mattdamon108 That'd just use an
orfilter: