diff --git a/src/client/mod.rs b/src/client/mod.rs index c29fdc9f29..1500c2628e 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -68,10 +68,10 @@ use url::ParseError as UrlError; use header::{Headers, Header, HeaderFormat}; use header::{ContentLength, Host, Location}; use method::Method; -use net::{NetworkConnector, NetworkStream}; +use net::{HttpConnector, NetworkConnector, NetworkStream, SslClient}; use Error; -use self::proxy::tunnel; +use self::proxy::{Proxy, tunnel}; pub use self::pool::Pool; pub use self::request::Request; pub use self::response::Response; @@ -84,6 +84,11 @@ pub mod response; use http::Protocol; use http::h1::Http11Protocol; +/// Proxy server configuration with a custom TLS wrapper. +pub struct ProxyConfig(pub H, pub u16, pub S) +where H: Into>, + S: SslClient<::Stream> + Send + Sync + 'static; + /// A Client to use additional features with Requests. /// /// Clients can handle things such as: redirect policy, connection pooling. @@ -127,6 +132,21 @@ impl Client { client } + pub fn with_proxy_config(proxy_config: ProxyConfig) -> Client + where H: Into>, + S: SslClient<::Stream> + Send + Sync + 'static { + let host = proxy_config.0.into(); + let port = proxy_config.1; + let proxy = Proxy { + connector: HttpConnector, + proxy: (host.clone(), port), + ssl: proxy_config.2 + }; + let mut client = Client::with_connector(Pool::with_connector(Default::default(), proxy)); + client.proxy = Some((host, port)); + client + } + /// Create a new client with a specific connector. pub fn with_connector(connector: C) -> Client where C: NetworkConnector + Send + Sync + 'static, S: NetworkStream + Send {