|
@@ -5,14 +5,13 @@ pub use self::codec::APCodec;
|
|
pub use self::handshake::handshake;
|
|
pub use self::handshake::handshake;
|
|
|
|
|
|
use futures::{Future, Sink, Stream};
|
|
use futures::{Future, Sink, Stream};
|
|
-use hyper::Uri;
|
|
|
|
use protobuf::{self, Message};
|
|
use protobuf::{self, Message};
|
|
use std::io;
|
|
use std::io;
|
|
use std::net::ToSocketAddrs;
|
|
use std::net::ToSocketAddrs;
|
|
-use std::str::FromStr;
|
|
|
|
use tokio_core::net::TcpStream;
|
|
use tokio_core::net::TcpStream;
|
|
use tokio_core::reactor::Handle;
|
|
use tokio_core::reactor::Handle;
|
|
use tokio_io::codec::Framed;
|
|
use tokio_io::codec::Framed;
|
|
|
|
+use url::Url;
|
|
|
|
|
|
use authentication::Credentials;
|
|
use authentication::Credentials;
|
|
use version;
|
|
use version;
|
|
@@ -24,22 +23,12 @@ pub type Transport = Framed<TcpStream, APCodec>;
|
|
pub fn connect(
|
|
pub fn connect(
|
|
addr: String,
|
|
addr: String,
|
|
handle: &Handle,
|
|
handle: &Handle,
|
|
- proxy: &Option<String>,
|
|
|
|
|
|
+ proxy: &Option<Url>,
|
|
) -> Box<Future<Item = Transport, Error = io::Error>> {
|
|
) -> Box<Future<Item = Transport, Error = io::Error>> {
|
|
let (addr, connect_url) = match *proxy {
|
|
let (addr, connect_url) = match *proxy {
|
|
Some(ref url) => {
|
|
Some(ref url) => {
|
|
- let url = Uri::from_str(url).expect("Malformed proxy address");
|
|
|
|
- let host = url.host().expect("Malformed proxy address: no host");
|
|
|
|
- let port = url.port().unwrap_or(3128);
|
|
|
|
-
|
|
|
|
- (
|
|
|
|
- format!("{}:{}", host, port)
|
|
|
|
- .to_socket_addrs()
|
|
|
|
- .unwrap()
|
|
|
|
- .next()
|
|
|
|
- .unwrap(),
|
|
|
|
- Some(addr.clone()),
|
|
|
|
- )
|
|
|
|
|
|
+ info!("Using proxy \"{}\"", url);
|
|
|
|
+ (url.to_socket_addrs().unwrap().next().unwrap(), Some(addr))
|
|
}
|
|
}
|
|
None => (addr.to_socket_addrs().unwrap().next().unwrap(), None),
|
|
None => (addr.to_socket_addrs().unwrap().next().unwrap(), None),
|
|
};
|
|
};
|