Move Agent construction to new AgentBuilder.
In the process, rename set_foo methods to just foo, since methods on the builder will always be setters. Adds a new() method on ConnectionPool so it can be constructed directly with the desired limits. Removes the setter methods on ConnectionPool for those limits. This means that connection limits can only be set when an Agent is built. There were two tests that verify Send and Sync implementations, one for Agent and one for Request. This PR moves the Request test to request.rs, and changes both tests to more directly verify the traits. There may be another way to do this, I'm not sure.
This commit is contained in:
committed by
Martin Algesten
parent
0f083a4436
commit
30162bf3bb
@@ -10,7 +10,9 @@ use super::super::*;
|
||||
|
||||
#[test]
|
||||
fn agent_reuse_headers() {
|
||||
let agent = agent().set("Authorization", "Foo 12345").build();
|
||||
let agent = AgentBuilder::new()
|
||||
.set("Authorization", "Foo 12345")
|
||||
.build();
|
||||
|
||||
test::set_handler("/agent_reuse_headers", |unit| {
|
||||
assert!(unit.has("Authorization"));
|
||||
@@ -44,7 +46,7 @@ fn idle_timeout_handler(mut stream: TcpStream) -> io::Result<()> {
|
||||
fn connection_reuse() {
|
||||
let testserver = TestServer::new(idle_timeout_handler);
|
||||
let url = format!("http://localhost:{}", testserver.port);
|
||||
let agent = Agent::default().build();
|
||||
let agent = Agent::default();
|
||||
let resp = agent.get(&url).call().unwrap();
|
||||
|
||||
// use up the connection so it gets returned to the pool
|
||||
@@ -87,8 +89,9 @@ fn custom_resolver() {
|
||||
buf
|
||||
});
|
||||
|
||||
crate::agent()
|
||||
.set_resolver(move |_: &str| Ok(vec![local_addr]))
|
||||
AgentBuilder::new()
|
||||
.resolver(move |_: &str| Ok(vec![local_addr]))
|
||||
.build()
|
||||
.get("http://cool.server/")
|
||||
.call()
|
||||
.ok();
|
||||
@@ -144,7 +147,7 @@ fn cookie_and_redirect(mut stream: TcpStream) -> io::Result<()> {
|
||||
fn test_cookies_on_redirect() -> Result<(), Error> {
|
||||
let testserver = TestServer::new(cookie_and_redirect);
|
||||
let url = format!("http://localhost:{}/first", testserver.port);
|
||||
let agent = Agent::default().build();
|
||||
let agent = Agent::default();
|
||||
agent.post(&url).call()?;
|
||||
assert!(agent.cookie("first").is_some());
|
||||
assert!(agent.cookie("second").is_some());
|
||||
@@ -168,7 +171,7 @@ fn dirty_streams_not_returned() -> Result<(), Error> {
|
||||
Ok(())
|
||||
});
|
||||
let url = format!("http://localhost:{}/", testserver.port);
|
||||
let agent = Agent::default().build();
|
||||
let agent = Agent::default();
|
||||
let resp = agent.get(&url).call()?;
|
||||
let resp_str = resp.into_string()?;
|
||||
assert_eq!(resp_str, "corgidachsund");
|
||||
|
||||
@@ -55,7 +55,7 @@ fn url_auth_overridden() {
|
||||
);
|
||||
test::make_response(200, "OK", vec![], vec![])
|
||||
});
|
||||
let agent = agent().auth("martin", "rubbermashgum").build();
|
||||
let agent = AgentBuilder::new().auth("martin", "rubbermashgum").build();
|
||||
let resp = agent
|
||||
.get("test://Aladdin:OpenSesame@host/url_auth_overridden")
|
||||
.call()
|
||||
|
||||
@@ -25,7 +25,7 @@ fn dribble_body_respond(mut stream: TcpStream, contents: &[u8]) -> io::Result<()
|
||||
}
|
||||
|
||||
fn get_and_expect_timeout(url: String) {
|
||||
let agent = Agent::default().build();
|
||||
let agent = Agent::default();
|
||||
let timeout = Duration::from_millis(500);
|
||||
let resp = agent.get(&url).timeout(timeout).call().unwrap();
|
||||
|
||||
@@ -86,7 +86,7 @@ fn overall_timeout_reading_json() {
|
||||
});
|
||||
let url = format!("http://localhost:{}/", server.port);
|
||||
|
||||
let agent = Agent::default().build();
|
||||
let agent = Agent::default();
|
||||
let timeout = Duration::from_millis(500);
|
||||
let resp = agent.get(&url).timeout(timeout).call().unwrap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user