Skip to content

Commit bca9a53

Browse files
committed
feat(net): Move SSL verification to unboxed closures
1 parent af57785 commit bca9a53

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/client/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ pub struct Client<C> {
4747
redirect_policy: RedirectPolicy,
4848
}
4949

50-
impl Client<HttpConnector> {
50+
impl<'v> Client<HttpConnector<'v>> {
5151

5252
/// Create a new Client.
53-
pub fn new() -> Client<HttpConnector> {
53+
pub fn new() -> Client<HttpConnector<'v>> {
5454
Client::with_connector(HttpConnector(None))
5555
}
5656

5757
/// Set the SSL verifier callback for use with OpenSSL.
58-
pub fn set_ssl_verifier(&mut self, verifier: ContextVerifier) {
58+
pub fn set_ssl_verifier(&mut self, verifier: ContextVerifier<'v>) {
5959
self.connector = HttpConnector(Some(verifier));
6060
}
6161

src/net.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,12 @@ impl NetworkStream for HttpStream {
309309

310310
/// A connector that will produce HttpStreams.
311311
#[allow(missing_copy_implementations)]
312-
pub struct HttpConnector(pub Option<ContextVerifier>);
312+
pub struct HttpConnector<'v>(pub Option<ContextVerifier<'v>>);
313313

314314
/// A method that can set verification methods on an SSL context
315-
pub type ContextVerifier = for <'a> fn(&'a mut SslContext) -> ();
315+
pub type ContextVerifier<'v> = Box<FnMut(&mut SslContext) -> ()+'v>;
316316

317-
impl NetworkConnector for HttpConnector {
317+
impl<'v> NetworkConnector for HttpConnector<'v> {
318318
type Stream = HttpStream;
319319

320320
fn connect(&mut self, host: &str, port: Port, scheme: &str) -> IoResult<HttpStream> {
@@ -328,8 +328,8 @@ impl NetworkConnector for HttpConnector {
328328
debug!("https scheme");
329329
let stream = try!(TcpStream::connect(addr));
330330
let mut context = try!(SslContext::new(Sslv23).map_err(lift_ssl_error));
331-
if let Some(ref v) = self.0 {
332-
v(&mut context);
331+
if let Some(ref mut verifier) = self.0 {
332+
verifier(&mut context);
333333
}
334334
let ssl = try!(Ssl::new(&context).map_err(lift_ssl_error));
335335
try!(ssl.set_hostname(host).map_err(lift_ssl_error));

0 commit comments

Comments
 (0)