Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
Formatted with 0.3.4-nightly.
  • Loading branch information
crawford committed Jan 8, 2018
1 parent 40669d1 commit 8b2e758
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
57 changes: 28 additions & 29 deletions src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ impl HttpsConnector {
let mut http = HttpConnector::new(threads, handle);
http.enforce_http(false);
let mut config = ClientConfig::new();
config.root_store.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
config
.root_store
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
config.ct_logs = Some(&ct_logs::LOGS);
HttpsConnector { http: http, tls_config: Arc::new(config) }
HttpsConnector {
http: http,
tls_config: Arc::new(config),
}
}
}

Expand Down Expand Up @@ -59,45 +64,39 @@ impl Service for HttpsConnector {
let host: DNSName = match uri.host() {
Some(host) => match DNSNameRef::try_from_ascii_str(host) {
Ok(host) => host.into(),
Err(err) => return HttpsConnecting(
Box::new(
::futures::future::err(
io::Error::new(
io::ErrorKind::InvalidInput,
format!("invalid url: {:?}", err),
)
)
)
),
Err(err) => {
return HttpsConnecting(Box::new(::futures::future::err(io::Error::new(
io::ErrorKind::InvalidInput,
format!("invalid url: {:?}", err),
))))
}
},
None => return HttpsConnecting(
Box::new(
::futures::future::err(
io::Error::new(
io::ErrorKind::InvalidInput,
"invalid url, missing host"
)
)
)
),
None => {
return HttpsConnecting(Box::new(::futures::future::err(io::Error::new(
io::ErrorKind::InvalidInput,
"invalid url, missing host",
))))
}
};
let connecting = self.http.call(uri);

HttpsConnecting(if is_https {
let tls = self.tls_config.clone();
Box::new(connecting.and_then(move |tcp| {
tls
.connect_async(host.as_ref(), tcp)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))
}).map(|tls| MaybeHttpsStream::Https(tls))
.map_err(|e| io::Error::new(io::ErrorKind::Other, e)))
Box::new(
connecting
.and_then(move |tcp| {
tls.connect_async(host.as_ref(), tcp)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))
})
.map(|tls| MaybeHttpsStream::Https(tls))
.map_err(|e| io::Error::new(io::ErrorKind::Other, e)),
)
} else {
Box::new(connecting.map(|tcp| MaybeHttpsStream::Http(tcp)))
})
}
}


pub struct HttpsConnecting(Box<Future<Item = MaybeHttpsStream, Error = io::Error>>);

impl Future for HttpsConnecting {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
//! }
//! ```

extern crate ct_logs;
extern crate futures;
extern crate hyper;
extern crate rustls;
Expand All @@ -34,7 +35,6 @@ extern crate tokio_rustls;
extern crate tokio_service;
extern crate webpki;
extern crate webpki_roots;
extern crate ct_logs;

mod connector;
mod stream;
Expand Down

0 comments on commit 8b2e758

Please sign in to comment.