Skip to content

Commit

Permalink
Merge pull request #825 from inejge/client-proxy-config
Browse files Browse the repository at this point in the history
Let the user specify a custom TLS wrapper for proxied connections
  • Loading branch information
seanmonstar authored Jun 14, 2016
2 parents a75adee + 0476196 commit 1b41567
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<H, S>(pub H, pub u16, pub S)
where H: Into<Cow<'static, str>>,
S: SslClient<<HttpConnector as NetworkConnector>::Stream> + Send + Sync + 'static;

/// A Client to use additional features with Requests.
///
/// Clients can handle things such as: redirect policy, connection pooling.
Expand Down Expand Up @@ -127,6 +132,21 @@ impl Client {
client
}

pub fn with_proxy_config<H, S>(proxy_config: ProxyConfig<H, S>) -> Client
where H: Into<Cow<'static, str>>,
S: SslClient<<HttpConnector as NetworkConnector>::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<C, S>(connector: C) -> Client
where C: NetworkConnector<Stream=S> + Send + Sync + 'static, S: NetworkStream + Send {
Expand Down

0 comments on commit 1b41567

Please sign in to comment.