mirror of
https://github.com/actix/actix-web.git
synced 2024-06-02 21:39:26 +00:00
Allow disabling redirect following in actix-test
If you're testing that redirects are being properly generated, then it's useful to not have the client go off on a wild goose chase of its own.
This commit is contained in:
parent
babac131d4
commit
1c5d7b51e4
|
@ -3,6 +3,7 @@
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
- Minimum supported Rust version (MSRV) is now 1.72.
|
- Minimum supported Rust version (MSRV) is now 1.72.
|
||||||
|
- Add `TestServerConfig::disable_redirects()` method.
|
||||||
|
|
||||||
## 0.1.3
|
## 0.1.3
|
||||||
|
|
||||||
|
|
|
@ -147,6 +147,8 @@ where
|
||||||
StreamType::Rustls022(_) => true,
|
StreamType::Rustls022(_) => true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let client_cfg = cfg.clone();
|
||||||
|
|
||||||
// run server in separate orphaned thread
|
// run server in separate orphaned thread
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
rt::System::new().block_on(async move {
|
rt::System::new().block_on(async move {
|
||||||
|
@ -416,7 +418,13 @@ where
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Client::builder().connector(connector).finish()
|
let mut client_builder = Client::builder().connector(connector);
|
||||||
|
|
||||||
|
if client_cfg.disable_redirects {
|
||||||
|
client_builder = client_builder.disable_redirects();
|
||||||
|
}
|
||||||
|
|
||||||
|
client_builder.finish()
|
||||||
};
|
};
|
||||||
|
|
||||||
TestServer {
|
TestServer {
|
||||||
|
@ -461,6 +469,7 @@ pub struct TestServerConfig {
|
||||||
client_request_timeout: Duration,
|
client_request_timeout: Duration,
|
||||||
port: u16,
|
port: u16,
|
||||||
workers: usize,
|
workers: usize,
|
||||||
|
disable_redirects: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for TestServerConfig {
|
impl Default for TestServerConfig {
|
||||||
|
@ -478,6 +487,7 @@ impl TestServerConfig {
|
||||||
client_request_timeout: Duration::from_secs(5),
|
client_request_timeout: Duration::from_secs(5),
|
||||||
port: 0,
|
port: 0,
|
||||||
workers: 1,
|
workers: 1,
|
||||||
|
disable_redirects: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -558,6 +568,15 @@ impl TestServerConfig {
|
||||||
self.workers = workers;
|
self.workers = workers;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Instruct the client to not follow redirects.
|
||||||
|
///
|
||||||
|
/// By default, the client will follow up to 10 consecutive redirects
|
||||||
|
/// before giving up.
|
||||||
|
pub fn disable_redirects(mut self) -> Self {
|
||||||
|
self.disable_redirects = true;
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A basic HTTP server controller that simplifies the process of writing integration tests for
|
/// A basic HTTP server controller that simplifies the process of writing integration tests for
|
||||||
|
|
Loading…
Reference in a new issue