Function warp::filters::header::header[][src]

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

Create a Filter that tries to parse the specified header.

This Filter will look for a header with supplied name, and try to parse to a T, otherwise rejects the request.

Example

use std::net::SocketAddr;

// Parse `content-length: 100` as a `u64`
let content_length = warp::header::<u64>("content-length");

// Parse `host: 127.0.0.1:8080` as a `SocketAddr
let local_host = warp::header::<SocketAddr>("host");

// Parse `foo: bar` into a `String`
let foo = warp::header::<String>("foo");