Skip to content

Commit

Permalink
Merge pull request #69 from erickt/master
Browse files Browse the repository at this point in the history
Optionally disable pulling in the tokio runtime
  • Loading branch information
ctz authored Mar 15, 2019
2 parents 8925936 + ee70519 commit a94d2a9
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ before_script:

script:
- cargo test
- cargo test --all-features
- cargo test --no-default-features
- bash -c 'if [[ "$TRAVIS_RUST_VERSION" == "$CLIPPY_RUST_VERSION" ]]; then
cargo clippy -- -D warnings;
fi'
20 changes: 17 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,29 @@ repository = "https://github.com/ctz/hyper-rustls"

[dependencies]
bytes = "0.4"
ct-logs = "0.5"
ct-logs = { version = "0.5", optional = true }
futures = "0.1.21"
hyper = "0.12.14"
hyper = { version = "0.12.14", default-features = false }
rustls = "0.15"
tokio-io = "0.1.1"
tokio-rustls = "0.9"
webpki = "0.19.0"
webpki-roots = "0.16"
webpki-roots = { version = "0.16", optional = true }

[dev-dependencies]
tokio = "0.1"
tokio-tcp = "0.1"

[features]
default = ["tokio-runtime"]
tokio-runtime = ["hyper/runtime", "ct-logs", "webpki-roots"]

[[example]]
name = "client"
path = "examples/client.rs"
required-features = ["tokio-runtime"]

[[example]]
name = "server"
path = "examples/server.rs"
required-features = ["tokio-runtime"]
7 changes: 5 additions & 2 deletions src/connector.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use ct_logs;
use futures::{Future, Poll};
use hyper::client::connect::{self, Connect};
#[cfg(feature = "tokio-runtime")]
use hyper::client::HttpConnector;
use rustls::{ClientConfig, Session};
use std::sync::Arc;
use std::{fmt, io};
use tokio_rustls::TlsConnector;
use webpki::{DNSName, DNSNameRef};
use webpki_roots;

use stream::MaybeHttpsStream;

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

#[cfg(feature = "tokio-runtime")]
impl HttpsConnector<HttpConnector> {
/// Construct a new `HttpsConnector`.
///
/// Takes number of DNS worker threads.
pub fn new(threads: usize) -> Self {
use ct_logs;
use webpki_roots;

let mut http = HttpConnector::new(threads);
http.enforce_http(false);
let mut config = ClientConfig::new();
Expand Down
28 changes: 16 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,36 @@
//! ## Example
//!
//! ```no_run
//! extern crate hyper;
//! extern crate hyper_rustls;
//! extern crate tokio;
//!
//! # #[cfg(feature = "tokio-runtime")]
//! # extern crate hyper;
//! #
//! # #[cfg(feature = "tokio-runtime")]
//! # fn main() {
//! use hyper::{Body, Client, StatusCode, Uri};
//!
//! fn main() {
//! let mut rt = tokio::runtime::Runtime::new().unwrap();
//! let url = ("https://hyper.rs").parse().unwrap();
//! let https = hyper_rustls::HttpsConnector::new(4);
//! let mut rt = tokio::runtime::Runtime::new().unwrap();
//! let url = ("https://hyper.rs").parse().unwrap();
//! let https = hyper_rustls::HttpsConnector::new(4);
//!
//! let client: Client<_, hyper::Body> = Client::builder().build(https);
//! let client: Client<_, hyper::Body> = Client::builder().build(https);
//!
//! let res = rt.block_on(client.get(url)).unwrap();
//! assert_eq!(res.status(), StatusCode::OK);
//! }
//! let res = rt.block_on(client.get(url)).unwrap();
//! assert_eq!(res.status(), StatusCode::OK);
//! # }
//! # #[cfg(not(feature = "tokio-runtime"))]
//! # fn main() {}
//! ```
extern crate bytes;
#[cfg(feature = "tokio-runtime")]
extern crate ct_logs;
extern crate futures;
extern crate hyper;
extern crate rustls;
extern crate tokio_io;
extern crate tokio_rustls;
extern crate webpki;
#[cfg(feature = "tokio-runtime")]
extern crate webpki_roots;

mod connector;
Expand Down

0 comments on commit a94d2a9

Please sign in to comment.