Function warp::filters::reply::headers

source ·
pub fn headers(headers: HeaderMap) -> WithHeaders
Expand description

Wrap a Filter that adds multiple headers to the reply.

§Note

This only adds a header if the underlying filter is successful, and returns a Reply If the underlying filter was rejected, the header is not added.

§Example

use warp::http::header::{HeaderMap, HeaderValue};
use warp::Filter;

let mut headers = HeaderMap::new();
headers.insert("server", HeaderValue::from_static("wee/0"));
headers.insert("foo", HeaderValue::from_static("bar"));

// Always set `server: wee/0` and `foo: bar` headers.
let route = warp::any()
    .map(warp::reply)
    .with(warp::reply::with::headers(headers));