Skip to content

Commit f4556d5

Browse files
committed
fix(client): keep the underlying connector when setting an SSL verifier
The client no longer drops the old `Connector` instance, along with its entire context (such as the settings and pooled connections in the case of a `Pool` connector); rather, it passes the SSL verifier on to the `Connector` so that it uses it for any future connections that it needs to establish. A regression test is included. Closes #495
1 parent a5d632b commit f4556d5

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/client/mod.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use url::ParseError as UrlError;
4141
use header::{Headers, Header, HeaderFormat};
4242
use header::{ContentLength, Location};
4343
use method::Method;
44-
use net::{NetworkConnector, NetworkStream, HttpConnector, ContextVerifier};
44+
use net::{NetworkConnector, NetworkStream, ContextVerifier};
4545
use status::StatusClass::Redirection;
4646
use {Url};
4747
use Error;
@@ -85,10 +85,7 @@ impl Client {
8585

8686
/// Set the SSL verifier callback for use with OpenSSL.
8787
pub fn set_ssl_verifier(&mut self, verifier: ContextVerifier) {
88-
self.connector = with_connector(Pool::with_connector(
89-
Default::default(),
90-
HttpConnector(Some(verifier))
91-
));
88+
self.connector.set_ssl_verifier(verifier);
9289
}
9390

9491
/// Set the RedirectPolicy.
@@ -409,6 +406,8 @@ mod tests {
409406
use header::Server;
410407
use super::{Client, RedirectPolicy};
411408
use url::Url;
409+
use mock::ChannelMockConnector;
410+
use std::sync::mpsc::{self, TryRecvError};
412411

413412
mock_connector!(MockRedirectPolicy {
414413
"http://127.0.0.1" => "HTTP/1.1 301 Redirect\r\n\
@@ -455,4 +454,30 @@ mod tests {
455454
assert_eq!(res.headers.get(), Some(&Server("mock2".to_string())));
456455
}
457456

457+
/// Tests that the `Client::set_ssl_verifier` method does not drop the
458+
/// old connector, but rather delegates the change to the connector itself.
459+
#[test]
460+
fn test_client_set_ssl_verifer() {
461+
let (tx, rx) = mpsc::channel();
462+
let mut client = Client::with_connector(ChannelMockConnector::new(tx));
463+
464+
client.set_ssl_verifier(Box::new(|_| {}));
465+
466+
// Make sure that the client called the `set_ssl_verifier` method
467+
match rx.try_recv() {
468+
Ok(meth) => {
469+
assert_eq!(meth, "set_ssl_verifier");
470+
},
471+
_ => panic!("Expected a call to `set_ssl_verifier`"),
472+
};
473+
// Now make sure that no other method was called, as well as that
474+
// the connector is still alive (i.e. wasn't dropped by the client).
475+
match rx.try_recv() {
476+
Err(TryRecvError::Empty) => {},
477+
Err(TryRecvError::Disconnected) => {
478+
panic!("Expected the connector to still be alive.");
479+
},
480+
Ok(_) => panic!("Did not expect any more method calls."),
481+
};
482+
}
458483
}

0 commit comments

Comments
 (0)