mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-07 00:00:12 +02:00
Change TestClient to not follow redirects (#715)
Makes it more obvious what actually goes on
This commit is contained in:
@@ -321,9 +321,9 @@ async fn with_trailing_slash() {
|
|||||||
|
|
||||||
let client = TestClient::new(app);
|
let client = TestClient::new(app);
|
||||||
|
|
||||||
// `TestClient` automatically follows redirects
|
|
||||||
let res = client.get("/foo/").send().await;
|
let res = client.get("/foo/").send().await;
|
||||||
assert_eq!(res.status(), StatusCode::OK);
|
assert_eq!(res.status(), StatusCode::PERMANENT_REDIRECT);
|
||||||
|
assert_eq!(res.headers().get("location").unwrap(), "/foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -332,9 +332,9 @@ async fn without_trailing_slash() {
|
|||||||
|
|
||||||
let client = TestClient::new(app);
|
let client = TestClient::new(app);
|
||||||
|
|
||||||
// `TestClient` automatically follows redirects
|
|
||||||
let res = client.get("/foo").send().await;
|
let res = client.get("/foo").send().await;
|
||||||
assert_eq!(res.status(), StatusCode::OK);
|
assert_eq!(res.status(), StatusCode::PERMANENT_REDIRECT);
|
||||||
|
assert_eq!(res.headers().get("location").unwrap(), "/foo/");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -363,7 +363,8 @@ async fn with_trailing_slash_post() {
|
|||||||
|
|
||||||
// `TestClient` automatically follows redirects
|
// `TestClient` automatically follows redirects
|
||||||
let res = client.post("/foo/").send().await;
|
let res = client.post("/foo/").send().await;
|
||||||
assert_eq!(res.status(), StatusCode::OK);
|
assert_eq!(res.status(), StatusCode::PERMANENT_REDIRECT);
|
||||||
|
assert_eq!(res.headers().get("location").unwrap(), "/foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
// for https://github.com/tokio-rs/axum/issues/681
|
// for https://github.com/tokio-rs/axum/issues/681
|
||||||
@@ -373,9 +374,9 @@ async fn without_trailing_slash_post() {
|
|||||||
|
|
||||||
let client = TestClient::new(app);
|
let client = TestClient::new(app);
|
||||||
|
|
||||||
// `TestClient` automatically follows redirects
|
|
||||||
let res = client.post("/foo").send().await;
|
let res = client.post("/foo").send().await;
|
||||||
assert_eq!(res.status(), StatusCode::OK);
|
assert_eq!(res.status(), StatusCode::PERMANENT_REDIRECT);
|
||||||
|
assert_eq!(res.headers().get("location").unwrap(), "/foo/");
|
||||||
}
|
}
|
||||||
|
|
||||||
// for https://github.com/tokio-rs/axum/issues/420
|
// for https://github.com/tokio-rs/axum/issues/420
|
||||||
|
|||||||
@@ -45,10 +45,12 @@ impl TestClient {
|
|||||||
server.await.expect("server error");
|
server.await.expect("server error");
|
||||||
});
|
});
|
||||||
|
|
||||||
TestClient {
|
let client = reqwest::Client::builder()
|
||||||
client: reqwest::Client::new(),
|
.redirect(reqwest::redirect::Policy::none())
|
||||||
addr,
|
.build()
|
||||||
}
|
.unwrap();
|
||||||
|
|
||||||
|
TestClient { client, addr }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get(&self, url: &str) -> RequestBuilder {
|
pub(crate) fn get(&self, url: &str) -> RequestBuilder {
|
||||||
|
|||||||
Reference in New Issue
Block a user