Merge pull request #8 from anowell/native-tls-update
Update to reflect latest native-tls API
This commit is contained in:
@@ -3,13 +3,14 @@ use std::net::SocketAddr;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use hyper::net::{SslClient, HttpStream, NetworkStream};
|
use hyper::net::{SslClient, HttpStream, NetworkStream};
|
||||||
use native_tls::{ClientBuilder, TlsStream as NativeTlsStream, HandshakeError};
|
use native_tls::{TlsConnector, TlsStream as NativeTlsStream, HandshakeError};
|
||||||
|
|
||||||
pub struct TlsClient(ClientBuilder);
|
pub struct TlsClient(TlsConnector);
|
||||||
|
|
||||||
impl TlsClient {
|
impl TlsClient {
|
||||||
pub fn new() -> ::Result<TlsClient> {
|
pub fn new() -> ::Result<TlsClient> {
|
||||||
ClientBuilder::new()
|
TlsConnector::builder()
|
||||||
|
.and_then(|c| c.build())
|
||||||
.map(TlsClient)
|
.map(TlsClient)
|
||||||
.map_err(|e| ::Error::Http(::hyper::Error::Ssl(Box::new(e))))
|
.map_err(|e| ::Error::Http(::hyper::Error::Ssl(Box::new(e))))
|
||||||
}
|
}
|
||||||
@@ -19,7 +20,7 @@ impl SslClient for TlsClient {
|
|||||||
type Stream = TlsStream;
|
type Stream = TlsStream;
|
||||||
|
|
||||||
fn wrap_client(&self, stream: HttpStream, host: &str) -> ::hyper::Result<Self::Stream> {
|
fn wrap_client(&self, stream: HttpStream, host: &str) -> ::hyper::Result<Self::Stream> {
|
||||||
self.0.handshake(host, stream).map(TlsStream).map_err(|e| {
|
self.0.connect(host, stream).map(TlsStream).map_err(|e| {
|
||||||
match e {
|
match e {
|
||||||
HandshakeError::Failure(e) => ::hyper::Error::Ssl(Box::new(e)),
|
HandshakeError::Failure(e) => ::hyper::Error::Ssl(Box::new(e)),
|
||||||
HandshakeError::Interrupted(..) => {
|
HandshakeError::Interrupted(..) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user