Skip to content

Commit ee70519

Browse files
committed
Optionally disable pulling in the tokio runtime
Before this patch, hyper-rustls required pulling in the tokio runtime due to it's use of `hyper::client::HttpConnector`. Unfortunately Fuchsia does not support tokio, which prevents our use of this library. This PR allows us to optionally disable pulling in tokio, and instead swap in our own version of the hyper `HttpConnector`.
1 parent 8925936 commit ee70519

File tree

4 files changed

+40
-17
lines changed

4 files changed

+40
-17
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ before_script:
2020

2121
script:
2222
- cargo test
23+
- cargo test --all-features
24+
- cargo test --no-default-features
2325
- bash -c 'if [[ "$TRAVIS_RUST_VERSION" == "$CLIPPY_RUST_VERSION" ]]; then
2426
cargo clippy -- -D warnings;
2527
fi'

Cargo.toml

+17-3
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,29 @@ repository = "https://github.com/ctz/hyper-rustls"
1010

1111
[dependencies]
1212
bytes = "0.4"
13-
ct-logs = "0.5"
13+
ct-logs = { version = "0.5", optional = true }
1414
futures = "0.1.21"
15-
hyper = "0.12.14"
15+
hyper = { version = "0.12.14", default-features = false }
1616
rustls = "0.15"
1717
tokio-io = "0.1.1"
1818
tokio-rustls = "0.9"
1919
webpki = "0.19.0"
20-
webpki-roots = "0.16"
20+
webpki-roots = { version = "0.16", optional = true }
2121

2222
[dev-dependencies]
2323
tokio = "0.1"
2424
tokio-tcp = "0.1"
25+
26+
[features]
27+
default = ["tokio-runtime"]
28+
tokio-runtime = ["hyper/runtime", "ct-logs", "webpki-roots"]
29+
30+
[[example]]
31+
name = "client"
32+
path = "examples/client.rs"
33+
required-features = ["tokio-runtime"]
34+
35+
[[example]]
36+
name = "server"
37+
path = "examples/server.rs"
38+
required-features = ["tokio-runtime"]

src/connector.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
use ct_logs;
21
use futures::{Future, Poll};
32
use hyper::client::connect::{self, Connect};
3+
#[cfg(feature = "tokio-runtime")]
44
use hyper::client::HttpConnector;
55
use rustls::{ClientConfig, Session};
66
use std::sync::Arc;
77
use std::{fmt, io};
88
use tokio_rustls::TlsConnector;
99
use webpki::{DNSName, DNSNameRef};
10-
use webpki_roots;
1110

1211
use stream::MaybeHttpsStream;
1312

@@ -18,11 +17,15 @@ pub struct HttpsConnector<T> {
1817
tls_config: Arc<ClientConfig>,
1918
}
2019

20+
#[cfg(feature = "tokio-runtime")]
2121
impl HttpsConnector<HttpConnector> {
2222
/// Construct a new `HttpsConnector`.
2323
///
2424
/// Takes number of DNS worker threads.
2525
pub fn new(threads: usize) -> Self {
26+
use ct_logs;
27+
use webpki_roots;
28+
2629
let mut http = HttpConnector::new(threads);
2730
http.enforce_http(false);
2831
let mut config = ClientConfig::new();

src/lib.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,36 @@
55
//! ## Example
66
//!
77
//! ```no_run
8-
//! extern crate hyper;
9-
//! extern crate hyper_rustls;
10-
//! extern crate tokio;
11-
//!
8+
//! # #[cfg(feature = "tokio-runtime")]
9+
//! # extern crate hyper;
10+
//! #
11+
//! # #[cfg(feature = "tokio-runtime")]
12+
//! # fn main() {
1213
//! use hyper::{Body, Client, StatusCode, Uri};
1314
//!
14-
//! fn main() {
15-
//! let mut rt = tokio::runtime::Runtime::new().unwrap();
16-
//! let url = ("https://hyper.rs").parse().unwrap();
17-
//! let https = hyper_rustls::HttpsConnector::new(4);
15+
//! let mut rt = tokio::runtime::Runtime::new().unwrap();
16+
//! let url = ("https://hyper.rs").parse().unwrap();
17+
//! let https = hyper_rustls::HttpsConnector::new(4);
1818
//!
19-
//! let client: Client<_, hyper::Body> = Client::builder().build(https);
19+
//! let client: Client<_, hyper::Body> = Client::builder().build(https);
2020
//!
21-
//! let res = rt.block_on(client.get(url)).unwrap();
22-
//! assert_eq!(res.status(), StatusCode::OK);
23-
//! }
21+
//! let res = rt.block_on(client.get(url)).unwrap();
22+
//! assert_eq!(res.status(), StatusCode::OK);
23+
//! # }
24+
//! # #[cfg(not(feature = "tokio-runtime"))]
25+
//! # fn main() {}
2426
//! ```
2527
2628
extern crate bytes;
29+
#[cfg(feature = "tokio-runtime")]
2730
extern crate ct_logs;
2831
extern crate futures;
2932
extern crate hyper;
3033
extern crate rustls;
3134
extern crate tokio_io;
3235
extern crate tokio_rustls;
3336
extern crate webpki;
37+
#[cfg(feature = "tokio-runtime")]
3438
extern crate webpki_roots;
3539

3640
mod connector;

0 commit comments

Comments
 (0)