summaryrefslogtreecommitdiffstats
path: root/third_party/rust/warp/tests/redirect.rs
blob: be7fd33e4a6d9c02007d3f9e220e7fe03e7a90d2 (plain)
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
#![deny(warnings)]
use warp::{http::Uri, Filter};

#[tokio::test]
async fn redirect_uri() {
    let over_there = warp::any().map(|| warp::redirect(Uri::from_static("/over-there")));

    let req = warp::test::request();
    let resp = req.reply(&over_there).await;

    assert_eq!(resp.status(), 301);
    assert_eq!(resp.headers()["location"], "/over-there");
}

#[tokio::test]
async fn redirect_found_uri() {
    let over_there = warp::any().map(|| warp::redirect::found(Uri::from_static("/over-there")));

    let req = warp::test::request();
    let resp = req.reply(&over_there).await;

    assert_eq!(resp.status(), 302);
    assert_eq!(resp.headers()["location"], "/over-there");
}

#[tokio::test]
async fn redirect_see_other_uri() {
    let over_there = warp::any().map(|| warp::redirect::see_other(Uri::from_static("/over-there")));

    let req = warp::test::request();
    let resp = req.reply(&over_there).await;

    assert_eq!(resp.status(), 303);
    assert_eq!(resp.headers()["location"], "/over-there");
}

#[tokio::test]
async fn redirect_temporary_uri() {
    let over_there = warp::any().map(|| warp::redirect::temporary(Uri::from_static("/over-there")));

    let req = warp::test::request();
    let resp = req.reply(&over_there).await;

    assert_eq!(resp.status(), 307);
    assert_eq!(resp.headers()["location"], "/over-there");
}

#[tokio::test]
async fn redirect_permanent_uri() {
    let over_there = warp::any().map(|| warp::redirect::permanent(Uri::from_static("/over-there")));

    let req = warp::test::request();
    let resp = req.reply(&over_there).await;

    assert_eq!(resp.status(), 308);
    assert_eq!(resp.headers()["location"], "/over-there");
}