refactor(net): NetworkConnecter no longer is for static usage
Instead, you can use an instance of a NetworkConnector with `Request::with_connector`. This allows overloading of the NetworkStream constructors, so that it is easy to modify how an `HttpStream` is created, while still relying on the rest of the stream implementation. BREAKING CHANGE
This commit is contained in:
@@ -92,8 +92,10 @@ impl net::NetworkStream for MockStream {
|
||||
}
|
||||
}
|
||||
|
||||
impl net::NetworkConnector for MockStream {
|
||||
fn connect<To: ToSocketAddr>(_addr: To, _scheme: &str) -> IoResult<MockStream> {
|
||||
struct MockConnector;
|
||||
|
||||
impl net::NetworkConnector<MockStream> for MockConnector {
|
||||
fn connect<To: ToSocketAddr>(&mut self, _addr: To, _scheme: &str) -> IoResult<MockStream> {
|
||||
Ok(MockStream::new())
|
||||
}
|
||||
|
||||
@@ -103,8 +105,9 @@ impl net::NetworkConnector for MockStream {
|
||||
fn bench_mock_hyper(b: &mut test::Bencher) {
|
||||
let url = "http://127.0.0.1:1337/";
|
||||
b.iter(|| {
|
||||
let mut req = hyper::client::Request::with_stream::<MockStream>(
|
||||
hyper::Get, hyper::Url::parse(url).unwrap()).unwrap();
|
||||
let mut req = hyper::client::Request::with_connector(
|
||||
hyper::Get, hyper::Url::parse(url).unwrap(), &mut MockConnector
|
||||
).unwrap();
|
||||
req.headers_mut().set(Foo);
|
||||
|
||||
req
|
||||
|
||||
Reference in New Issue
Block a user