mirror of
https://github.com/tokio-rs/axum.git
synced 2025-03-22 23:15:31 +01:00
Change TestClient
to not follow redirects (#715)
Makes it more obvious what actually goes on
This commit is contained in:
parent
50f42d8071
commit
830bfdbe3c
2 changed files with 14 additions and 11 deletions
axum/src
|
@ -321,9 +321,9 @@ async fn with_trailing_slash() {
|
|||
|
||||
let client = TestClient::new(app);
|
||||
|
||||
// `TestClient` automatically follows redirects
|
||||
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]
|
||||
|
@ -332,9 +332,9 @@ async fn without_trailing_slash() {
|
|||
|
||||
let client = TestClient::new(app);
|
||||
|
||||
// `TestClient` automatically follows redirects
|
||||
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]
|
||||
|
@ -363,7 +363,8 @@ async fn with_trailing_slash_post() {
|
|||
|
||||
// `TestClient` automatically follows redirects
|
||||
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
|
||||
|
@ -373,9 +374,9 @@ async fn without_trailing_slash_post() {
|
|||
|
||||
let client = TestClient::new(app);
|
||||
|
||||
// `TestClient` automatically follows redirects
|
||||
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
|
||||
|
|
|
@ -45,10 +45,12 @@ impl TestClient {
|
|||
server.await.expect("server error");
|
||||
});
|
||||
|
||||
TestClient {
|
||||
client: reqwest::Client::new(),
|
||||
addr,
|
||||
}
|
||||
let client = reqwest::Client::builder()
|
||||
.redirect(reqwest::redirect::Policy::none())
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
TestClient { client, addr }
|
||||
}
|
||||
|
||||
pub(crate) fn get(&self, url: &str) -> RequestBuilder {
|
||||
|
|
Loading…
Add table
Reference in a new issue