feat(client): add a new Client struct with super powers

- Includes ergonomic traits like IntoUrl and IntoBody, allowing easy
usage.
- Client can have a RedirectPolicy.
- Client can have a SslVerifier.

Updated benchmarks for client. (Disabled rust-http client bench since it
hangs.)
This commit is contained in:
Sean McArthur
2014-10-17 14:59:01 -07:00
parent 9e99c57fa8
commit 8c83a3358e
13 changed files with 505 additions and 89 deletions

View File

@@ -73,3 +73,35 @@ impl NetworkConnector<MockStream> for MockConnector {
Ok(MockStream::new())
}
}
/// new connectors must be created if you wish to intercept requests.
macro_rules! mock_connector (
($name:ident {
$($url:expr => $res:expr)*
}) => (
struct $name;
impl ::net::NetworkConnector<::mock::MockStream> for $name {
fn connect(&mut self, host: &str, port: u16, scheme: &str) -> ::std::io::IoResult<::mock::MockStream> {
use std::collections::HashMap;
debug!("MockStream::connect({}, {}, {})", host, port, scheme);
let mut map = HashMap::new();
$(map.insert($url, $res);)*
let key = format!("{}://{}", scheme, host);
// ignore port for now
match map.find(&&*key) {
Some(res) => Ok(::mock::MockStream {
write: ::std::io::MemWriter::new(),
read: ::std::io::MemReader::new(res.to_string().into_bytes())
}),
None => panic!("{} doesn't know url {}", stringify!($name), key)
}
}
}
)
)