feat(net): Move SSL verification to unboxed closures
This commit is contained in:
		| @@ -47,15 +47,15 @@ pub struct Client<C> { | ||||
|     redirect_policy: RedirectPolicy, | ||||
| } | ||||
|  | ||||
| impl Client<HttpConnector> { | ||||
| impl<'v> Client<HttpConnector<'v>> { | ||||
|  | ||||
|     /// Create a new Client. | ||||
|     pub fn new() -> Client<HttpConnector> { | ||||
|     pub fn new() -> Client<HttpConnector<'v>> { | ||||
|         Client::with_connector(HttpConnector(None)) | ||||
|     } | ||||
|  | ||||
|     /// Set the SSL verifier callback for use with OpenSSL. | ||||
|     pub fn set_ssl_verifier(&mut self, verifier: ContextVerifier) { | ||||
|     pub fn set_ssl_verifier(&mut self, verifier: ContextVerifier<'v>) { | ||||
|         self.connector = HttpConnector(Some(verifier)); | ||||
|     } | ||||
|  | ||||
|   | ||||
							
								
								
									
										10
									
								
								src/net.rs
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/net.rs
									
									
									
									
									
								
							| @@ -309,12 +309,12 @@ impl NetworkStream for HttpStream { | ||||
|  | ||||
| /// A connector that will produce HttpStreams. | ||||
| #[allow(missing_copy_implementations)] | ||||
| pub struct HttpConnector(pub Option<ContextVerifier>); | ||||
| pub struct HttpConnector<'v>(pub Option<ContextVerifier<'v>>); | ||||
|  | ||||
| /// A method that can set verification methods on an SSL context | ||||
| pub type ContextVerifier = for <'a> fn(&'a mut SslContext) -> (); | ||||
| pub type ContextVerifier<'v> = Box<FnMut(&mut SslContext) -> ()+'v>; | ||||
|  | ||||
| impl NetworkConnector for HttpConnector { | ||||
| impl<'v> NetworkConnector for HttpConnector<'v> { | ||||
|     type Stream = HttpStream; | ||||
|  | ||||
|     fn connect(&mut self, host: &str, port: Port, scheme: &str) -> IoResult<HttpStream> { | ||||
| @@ -328,8 +328,8 @@ impl NetworkConnector for HttpConnector { | ||||
|                 debug!("https scheme"); | ||||
|                 let stream = try!(TcpStream::connect(addr)); | ||||
|                 let mut context = try!(SslContext::new(Sslv23).map_err(lift_ssl_error)); | ||||
|                 if let Some(ref v) = self.0 { | ||||
|                     v(&mut context); | ||||
|                 if let Some(ref mut verifier) = self.0 { | ||||
|                     verifier(&mut context); | ||||
|                 } | ||||
|                 let ssl = try!(Ssl::new(&context).map_err(lift_ssl_error)); | ||||
|                 try!(ssl.set_hostname(host).map_err(lift_ssl_error)); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user