pub fn optional<T>(
    name: &'static str
) -> impl Filter<Extract = (Option<T>,), Error = Rejection> + Copy where
    T: FromStr + Send + 'static, 
Expand description

Create a Filter that tries to parse the specified header, if it exists.

If the header does not exist, it yields None. Otherwise, it will try to parse as a T, and if it fails, a invalid header rejection is return. If successful, the filter yields Some(T).

Example

// Grab the `authorization` header if it exists.
let opt_auth = warp::header::optional::<String>("authorization");
Examples found in repository?
src/filters/sse.rs (line 232)
228
229
230
231
232
233
pub fn last_event_id<T>() -> impl Filter<Extract = One<Option<T>>, Error = Rejection> + Copy
where
    T: FromStr + Send + Sync + 'static,
{
    header::optional("last-event-id")
}