change Builders to only error at the end

Closes #189
This commit is contained in:
Sean McArthur
2017-08-31 11:45:24 -07:00
parent a02b388b2b
commit 779f8080ef
16 changed files with 390 additions and 313 deletions

View File

@@ -61,10 +61,9 @@ fn test_gzip(response_size: usize, chunk_size: usize) {
let mut core = Core::new().unwrap();
let client = Client::new(&core.handle()).unwrap();
let client = Client::new(&core.handle());
let res_future = client.get(&format!("http://{}/gzip", server.addr()))
.unwrap()
.send()
.and_then(|mut res| {
let body = mem::replace(res.body_mut(), Decoder::empty());

View File

@@ -62,9 +62,7 @@ fn test_post() {
let url = format!("http://{}/2", server.addr());
let mut res = reqwest::Client::new()
.unwrap()
.post(&url)
.unwrap()
.body("Hello")
.send()
.unwrap();

View File

@@ -68,10 +68,9 @@ fn test_gzip_empty_body() {
\r\n"
};
let client = reqwest::Client::new().unwrap();
let client = reqwest::Client::new();
let mut res = client
.head(&format!("http://{}/gzip", server.addr()))
.unwrap()
.send()
.unwrap();
@@ -127,11 +126,10 @@ fn test_accept_header_is_not_changed_if_set() {
\r\n\
"
};
let client = reqwest::Client::new().unwrap();
let client = reqwest::Client::new();
let res = client
.get(&format!("http://{}/accept", server.addr()))
.unwrap()
.header(reqwest::header::Accept::json())
.send()
.unwrap();
@@ -157,10 +155,9 @@ fn test_accept_encoding_header_is_not_changed_if_set() {
\r\n\
"
};
let client = reqwest::Client::new().unwrap();
let client = reqwest::Client::new();
let res = client.get(&format!("http://{}/accept-encoding", server.addr()))
.unwrap()
.header(reqwest::header::AcceptEncoding(
vec![reqwest::header::qitem(reqwest::header::Encoding::Identity)]
))

View File

@@ -38,9 +38,7 @@ fn test_multipart() {
let url = format!("http://{}/multipart/1", server.addr());
let res = reqwest::Client::new()
.unwrap()
.post(&url)
.unwrap()
.multipart(form)
.send()
.unwrap();

View File

@@ -26,12 +26,10 @@ fn test_http_proxy() {
let url = "http://hyper.rs/prox";
let res = reqwest::Client::builder()
.unwrap()
.proxy(reqwest::Proxy::http(&proxy).unwrap())
.build()
.unwrap()
.get(url)
.unwrap()
.send()
.unwrap();

View File

@@ -5,7 +5,7 @@ mod support;
#[test]
fn test_redirect_301_and_302_and_303_changes_post_to_get() {
let client = reqwest::Client::new().unwrap();
let client = reqwest::Client::new();
let codes = [301, 302, 303];
for code in codes.iter() {
@@ -47,7 +47,6 @@ fn test_redirect_301_and_302_and_303_changes_post_to_get() {
let url = format!("http://{}/{}", redirect.addr(), code);
let dst = format!("http://{}/{}", redirect.addr(), "dst");
let res = client.post(&url)
.unwrap()
.send()
.unwrap();
assert_eq!(res.url().as_str(), dst);
@@ -59,7 +58,7 @@ fn test_redirect_301_and_302_and_303_changes_post_to_get() {
#[test]
fn test_redirect_307_and_308_tries_to_get_again() {
let client = reqwest::Client::new().unwrap();
let client = reqwest::Client::new();
let codes = [307, 308];
for code in codes.iter() {
let redirect = server! {
@@ -100,7 +99,6 @@ fn test_redirect_307_and_308_tries_to_get_again() {
let url = format!("http://{}/{}", redirect.addr(), code);
let dst = format!("http://{}/{}", redirect.addr(), "dst");
let res = client.get(&url)
.unwrap()
.send()
.unwrap();
assert_eq!(res.url().as_str(), dst);
@@ -112,7 +110,7 @@ fn test_redirect_307_and_308_tries_to_get_again() {
#[test]
fn test_redirect_307_and_308_tries_to_post_again() {
let client = reqwest::Client::new().unwrap();
let client = reqwest::Client::new();
let codes = [307, 308];
for code in codes.iter() {
let redirect = server! {
@@ -157,7 +155,6 @@ fn test_redirect_307_and_308_tries_to_post_again() {
let url = format!("http://{}/{}", redirect.addr(), code);
let dst = format!("http://{}/{}", redirect.addr(), "dst");
let res = client.post(&url)
.unwrap()
.body("Hello")
.send()
.unwrap();
@@ -170,7 +167,7 @@ fn test_redirect_307_and_308_tries_to_post_again() {
#[test]
fn test_redirect_307_does_not_try_if_reader_cannot_reset() {
let client = reqwest::Client::new().unwrap();
let client = reqwest::Client::new();
let codes = [307, 308];
for &code in codes.iter() {
let redirect = server! {
@@ -199,7 +196,6 @@ fn test_redirect_307_does_not_try_if_reader_cannot_reset() {
let url = format!("http://{}/{}", redirect.addr(), code);
let res = client
.post(&url)
.unwrap()
.body(reqwest::Body::new(&b"Hello"[..]))
.send()
.unwrap();
@@ -251,12 +247,10 @@ fn test_redirect_removes_sensitive_headers() {
let mut cookie = reqwest::header::Cookie::new();
cookie.set("foo", "bar");
reqwest::Client::builder()
.unwrap()
.referer(false)
.build()
.unwrap()
.get(&format!("http://{}/sensitive", mid_server.addr()))
.unwrap()
.header(cookie)
.send()
.unwrap();
@@ -309,12 +303,10 @@ fn test_redirect_policy_can_stop_redirects_without_an_error() {
let url = format!("http://{}/no-redirect", server.addr());
let res = reqwest::Client::builder()
.unwrap()
.redirect(reqwest::RedirectPolicy::none())
.build()
.unwrap()
.get(&url)
.unwrap()
.send()
.unwrap();
@@ -359,12 +351,12 @@ fn test_referer_is_not_set_if_disabled() {
\r\n\
"
};
reqwest::Client::builder().unwrap()
reqwest::Client::builder()
.referer(false)
.build().unwrap()
.build()
.unwrap()
//client
.get(&format!("http://{}/no-refer", server.addr()))
.unwrap()
.send()
.unwrap();
}

View File

@@ -30,12 +30,10 @@ fn test_write_timeout() {
let url = format!("http://{}/write-timeout", server.addr());
let err = reqwest::Client::builder()
.unwrap()
.timeout(Duration::from_millis(500))
.build()
.unwrap()
.post(&url)
.unwrap()
.header(reqwest::header::ContentLength(5))
.body(reqwest::Body::new(&b"Hello"[..]))
.send()
@@ -66,12 +64,10 @@ fn test_response_timeout() {
let url = format!("http://{}/response-timeout", server.addr());
let err = reqwest::Client::builder()
.unwrap()
.timeout(Duration::from_millis(500))
.build()
.unwrap()
.get(&url)
.unwrap()
.send()
.unwrap_err();
@@ -101,12 +97,10 @@ fn test_read_timeout() {
let url = format!("http://{}/read-timeout", server.addr());
let mut res = reqwest::Client::builder()
.unwrap()
.timeout(Duration::from_millis(500))
.build()
.unwrap()
.get(&url)
.unwrap()
.send()
.unwrap();