Merge branch 'release-2.0' into json_deserialize

This commit is contained in:
Jacob Hoffman-Andrews
2020-11-21 16:25:14 -08:00
17 changed files with 630 additions and 271 deletions

View File

@@ -1,5 +1,6 @@
#![allow(dead_code)]
use crate::error::Error;
use crate::testserver::{read_request, TestServer};
use std::io::{self, Read, Write};
use std::net::TcpStream;

View File

@@ -1,10 +1,10 @@
use crate::error::Error;
use crate::stream::Stream;
use crate::unit::Unit;
use crate::{error::Error};
use crate::{stream::Stream};
use once_cell::sync::Lazy;
use std::collections::HashMap;
use std::io::{Cursor, Write};
use std::sync::{Arc, Mutex};
use std::{collections::HashMap};
mod agent_test;
mod body_read;

View File

@@ -4,7 +4,7 @@ use std::{
};
use testserver::{self, TestServer};
use crate::test;
use crate::{error::Error, test};
use super::super::*;
@@ -34,7 +34,7 @@ fn redirect_many() {
.build()
.get("test://host/redirect_many1")
.call();
assert!(matches!(result, Err(Error::TooManyRedirects)));
assert!(matches!(result, Err(e) if e.kind() == ErrorKind::TooManyRedirects));
}
#[test]
@@ -104,12 +104,11 @@ fn redirect_host() {
Ok(())
});
let url = format!("http://localhost:{}/", srv.port);
let resp = crate::Agent::new().get(&url).call();
let err = resp.err();
let result = crate::Agent::new().get(&url).call();
assert!(
matches!(err, Some(Error::DnsFailed(_))),
"expected DnsFailed, got: {:?}",
err
matches!(result, Err(ref e) if e.kind() == ErrorKind::DnsFailed),
"expected Err(DnsFailed), got: {:?}",
result
);
}

View File

@@ -157,13 +157,13 @@ fn non_ascii_header() {
test::set_handler("/non_ascii_header", |_unit| {
test::make_response(200, "OK", vec!["Wörse: Hädör"], vec![])
});
let resp = get("test://host/non_ascii_header")
let result = get("test://host/non_ascii_header")
.set("Bäd", "Headör")
.call();
assert!(
matches!(resp, Err(Error::BadHeader)),
"expected Some(&BadHeader), got {:?}",
resp
matches!(result, Err(ref e) if e.kind() == ErrorKind::BadHeader),
"expected Err(BadHeader), got {:?}",
result
);
}

View File

@@ -1,8 +1,11 @@
use crate::testserver::*;
use std::io::{self, Write};
use std::net::TcpStream;
use std::thread;
use std::time::Duration;
use std::{
error::Error,
io::{self, Write},
};
use super::super::*;
@@ -96,10 +99,16 @@ fn read_timeout_during_headers() {
let server = TestServer::new(dribble_headers_respond);
let url = format!("http://localhost:{}/", server.port);
let agent = builder().timeout_read(Duration::from_millis(10)).build();
let resp = agent.get(&url).call();
match resp {
let result = agent.get(&url).call();
match result {
Ok(_) => Err("successful response".to_string()),
Err(Error::Io(e)) if e.kind() == io::ErrorKind::TimedOut => Ok(()),
Err(e) if e.kind() == ErrorKind::Io => {
let ioe: Option<&io::Error> = e.source().and_then(|s| s.downcast_ref());
match ioe {
Some(e) if e.kind() == io::ErrorKind::TimedOut => Ok(()),
_ => Err(format!("wrong error type {:?}", e)),
}
}
Err(e) => Err(format!("Unexpected error type: {:?}", e)),
}
.expect("expected timeout but got something else");
@@ -111,10 +120,16 @@ fn overall_timeout_during_headers() {
let server = TestServer::new(dribble_headers_respond);
let url = format!("http://localhost:{}/", server.port);
let agent = builder().timeout(Duration::from_millis(500)).build();
let resp = agent.get(&url).call();
match resp {
let result = agent.get(&url).call();
match result {
Ok(_) => Err("successful response".to_string()),
Err(Error::Io(e)) if e.kind() == io::ErrorKind::TimedOut => Ok(()),
Err(e) if e.kind() == ErrorKind::Io => {
let ioe: Option<&io::Error> = e.source().and_then(|s| s.downcast_ref());
match ioe {
Some(e) if e.kind() == io::ErrorKind::TimedOut => Ok(()),
_ => Err(format!("wrong error type {:?}", e)),
}
}
Err(e) => Err(format!("Unexpected error type: {:?}", e)),
}
.expect("expected timeout but got something else");