Skip to content

Commit

Permalink
feat(client): enable use of custom TLS wrapper for proxied connections
Browse files Browse the repository at this point in the history
The new struct ProxyConfig lets one specify a custom TLS wrapper for
proxied connections. The function Client::with_proxy_config takes an
instance of that struct and returns an appropriately initialized new
Client. The connector for talking to the proxy is still fixed to
HttpConnector.

Fixes hyperium#824
  • Loading branch information
inejge committed Jun 12, 2016
1 parent a75adee commit 452a87d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ use method::Method;
use net::{NetworkConnector, NetworkStream};
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 452a87d

Please sign in to comment.