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:
32
src/mock.rs
32
src/mock.rs
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user