Function warp::filters::header::optional

source ·
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");