Skip to content

Commit f51987a

Browse files
committed
Merge remote-tracking branch 'origin/pr/102'
2 parents 34adf9a + 5422cd9 commit f51987a

File tree

5 files changed

+45
-23
lines changed

5 files changed

+45
-23
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ before_script:
2020

2121
script:
2222
- cargo test
23-
- cargo test --all-features
23+
- cargo test --no-default-features --features native-tokio
24+
- cargo test --no-default-features --features webpki-tokio
2425
- cargo test --no-default-features
2526
- bash -c 'if [[ "$TRAVIS_RUST_VERSION" == "$CLIPPY_RUST_VERSION" ]]; then
2627
cargo clippy -- -D warnings;

Cargo.toml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,26 @@ homepage = "https://github.com/ctz/hyper-rustls"
1010
repository = "https://github.com/ctz/hyper-rustls"
1111

1212
[dependencies]
13-
bytes = "0.5.2"
13+
bytes = "0.5"
1414
log = "0.4.4"
15-
ct-logs = { version = "^0.6.0", optional = true }
15+
ct-logs = { version = "^0.6", optional = true }
1616
futures-util = "0.3.1"
1717
hyper = { version = "0.13.0", default-features = false }
1818
rustls = "0.16"
19+
rustls-native-certs = { version = "0.2.1", optional = true }
1920
tokio = "0.2.4"
2021
tokio-rustls = "0.12.1"
21-
webpki = "^0.21.0"
22-
rustls-native-certs = { version = "0.2.1", optional = true }
22+
webpki = "0.21.0"
23+
webpki-roots = { version = "0.19", optional = true }
2324

2425
[dev-dependencies]
25-
tokio = { version = "0.2.4", features = ["io-std", "macros", "dns", "stream"] }
26+
tokio = { version = "0.2", features = ["io-std", "macros", "dns", "stream"] }
2627

2728
[features]
28-
default = ["tokio-runtime"]
29-
tokio-runtime = ["hyper/runtime", "ct-logs", "rustls-native-certs"]
29+
default = ["native-tokio"]
30+
webpki-tokio = ["tokio-runtime", "webpki-roots"]
31+
native-tokio = ["tokio-runtime", "rustls-native-certs"]
32+
tokio-runtime = ["hyper/runtime", "ct-logs"]
3033

3134
[[example]]
3235
name = "client"

admin/pipelines/cargo-steps.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ steps:
55
- script: cargo test
66
displayName: "cargo test (debug; default features)"
77
env: { "RUST_BACKTRACE": "1" }
8-
- script: cargo test --all-features
9-
displayName: "cargo test (debug; all features)"
8+
- script: cargo test --no-default-features --features webpki-tokio
9+
displayName: "cargo test (debug; webpi-roots feature)"
1010
env: { "RUST_BACKTRACE": "1" }
1111
- script: cargo test --no-default-features
1212
displayName: "cargo build (debug; no default features)"

src/connector.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct HttpsConnector<T> {
2424
tls_config: Arc<ClientConfig>,
2525
}
2626

27-
#[cfg(feature = "tokio-runtime")]
27+
#[cfg(all(any(feature = "rustls-native-certs", feature = "webpki-roots"), feature = "tokio-runtime"))]
2828
impl HttpsConnector<HttpConnector> {
2929
/// Construct a new `HttpsConnector`.
3030
///
@@ -34,22 +34,31 @@ impl HttpsConnector<HttpConnector> {
3434
http.enforce_http(false);
3535
let mut config = ClientConfig::new();
3636
config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()];
37-
config.root_store = match rustls_native_certs::load_native_certs() {
38-
Ok(store) => store,
39-
Err((Some(store), err)) => {
40-
warn!("Could not load all certificates: {:?}", err);
41-
store
42-
}
43-
Err((None, err)) => {
44-
Err(err).expect("cannot access native cert store")
45-
}
46-
};
37+
#[cfg(feature = "rustls-native-certs")]
38+
{
39+
config.root_store = match rustls_native_certs::load_native_certs() {
40+
Ok(store) => store,
41+
Err((Some(store), err)) => {
42+
warn!("Could not load all certificates: {:?}", err);
43+
store
44+
}
45+
Err((None, err)) => {
46+
Err(err).expect("cannot access native cert store")
47+
}
48+
};
49+
}
50+
#[cfg(feature = "webpki-roots")]
51+
{
52+
config
53+
.root_store
54+
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
55+
}
4756
config.ct_logs = Some(&ct_logs::LOGS);
4857
(http, config).into()
4958
}
5059
}
5160

52-
#[cfg(feature = "tokio-runtime")]
61+
#[cfg(all(any(feature = "rustls-native-certs", feature = "webpki-roots"), feature = "tokio-runtime"))]
5362
impl Default for HttpsConnector<HttpConnector> {
5463
fn default() -> Self {
5564
Self::new()

src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! ## Example
66
//!
77
//! ```no_run
8-
//! # #[cfg(feature = "tokio-runtime")]
8+
//! # #[cfg(all(any(feature = "rustls-native-certs", feature = "webpki-roots"), feature = "tokio-runtime"))]
99
//! # fn main() {
1010
//! use hyper::{Body, Client, StatusCode, Uri};
1111
//!
@@ -22,6 +22,15 @@
2222
//! # fn main() {}
2323
//! ```
2424
25+
#[cfg(all(
26+
feature = "tokio-runtime",
27+
any(not(feature = "rustls-native-certs"), feature = "webpki-roots"),
28+
any(not(feature = "webpki-roots"), feature = "rustls-native-certs")
29+
))]
30+
compile_error!(
31+
"Must enable exactly one of rustls-native-certs (default) or webpki-roots with tokio-runtime! (note: use `default-features = false' in a binary crate for one or other)"
32+
);
33+
2534
mod connector;
2635
mod stream;
2736

0 commit comments

Comments
 (0)