Function warp::filters::header::header

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

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