1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#![deny(warnings)]
use warp::http::header::{HeaderMap, HeaderValue};
use warp::Filter;
#[tokio::test]
async fn header() {
let header = warp::reply::with::header("foo", "bar");
let no_header = warp::any().map(warp::reply).with(&header);
let req = warp::test::request();
let resp = req.reply(&no_header).await;
assert_eq!(resp.headers()["foo"], "bar");
let prev_header = warp::reply::with::header("foo", "sean");
let yes_header = warp::any().map(warp::reply).with(prev_header).with(header);
let req = warp::test::request();
let resp = req.reply(&yes_header).await;
assert_eq!(resp.headers()["foo"], "bar", "replaces header");
}
#[tokio::test]
async fn headers() {
let mut headers = HeaderMap::new();
headers.insert("server", HeaderValue::from_static("warp"));
headers.insert("foo", HeaderValue::from_static("bar"));
let headers = warp::reply::with::headers(headers);
let no_header = warp::any().map(warp::reply).with(&headers);
let req = warp::test::request();
let resp = req.reply(&no_header).await;
assert_eq!(resp.headers()["foo"], "bar");
assert_eq!(resp.headers()["server"], "warp");
let prev_header = warp::reply::with::header("foo", "sean");
let yes_header = warp::any().map(warp::reply).with(prev_header).with(headers);
let req = warp::test::request();
let resp = req.reply(&yes_header).await;
assert_eq!(resp.headers()["foo"], "bar", "replaces header");
}
#[tokio::test]
async fn default_header() {
let def_header = warp::reply::with::default_header("foo", "bar");
let no_header = warp::any().map(warp::reply).with(&def_header);
let req = warp::test::request();
let resp = req.reply(&no_header).await;
assert_eq!(resp.headers()["foo"], "bar");
let header = warp::reply::with::header("foo", "sean");
let yes_header = warp::any().map(warp::reply).with(header).with(def_header);
let req = warp::test::request();
let resp = req.reply(&yes_header).await;
assert_eq!(resp.headers()["foo"], "sean", "doesn't replace header");
}
|