Skip to content

Commit

Permalink
Merge pull request #125 from kiljacken/rustls
Browse files Browse the repository at this point in the history
Add rustls support behind a non-default feature.
  • Loading branch information
kestred authored Apr 13, 2020
2 parents b8a7d84 + 2a5e247 commit 3433cb1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ script:
- cargo fmt -- --check

# Check "no default features"
- cargo build --verbose --workspace --exclude binary_size --no-default-features
- cargo build --verbose --workspace --exclude binary_size --no-default-features --features default-tls

# Check "full/blocking"
- cargo build --verbose --workspace --exclude binary_size
Expand All @@ -45,3 +45,7 @@ script:
# Check "full/async
- cargo build --verbose --features async --workspace --exclude binary_size
- cargo test --verbose --features async --example async_create_charge

# Check "rustls-tls"
- cargo build --verbose --no-default-features --features "full webhook-events blocking rustls-tls" --workspace --exclude binary_size
- cargo test --verbose --no-default-features --features "full webhook-events blocking rustls-tls" --workspace --exclude binary_size
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ travis-ci = {repository = "wyyerd/stripe-rs"}
name = "stripe"

[features]
default = ["full", "webhook-events", "blocking"]
default = ["full", "webhook-events", "blocking", "default-tls"]
full = [
# "core",
# "payment-methods",
Expand Down Expand Up @@ -63,12 +63,16 @@ webhooks = ["webhook-endpoints", "webhook-events"]
blocking = ["tokio/rt-core"]
async = []

default-tls = ["hyper-tls"]
rustls-tls = ["hyper-rustls"]

[dependencies]
chrono = { version = "0.4", features = ["serde"] }
futures-util = { version = "0.3.1", default-features = false }
http = "0.2.0"
hyper = { version = "0.13", default-features = false, features = ["tcp"] }
hyper-tls = "0.4.0"
hyper-tls = { version = "0.4", optional = true }
hyper-rustls = { version = "0.19", optional = true }
serde = "1.0.79" # N.B. we use `serde(other)` which was introduced in `1.0.79`
serde_derive = "1.0.79"
serde_json = "1.0"
Expand Down
14 changes: 11 additions & 3 deletions src/client/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ use serde::de::DeserializeOwned;
use std::future::Future;
use std::pin::Pin;

type HttpClient =
hyper::Client<hyper_tls::HttpsConnector<hyper::client::HttpConnector>, hyper::Body>;
#[cfg(feature = "rustls-tls")]
use hyper_rustls::HttpsConnector;
#[cfg(feature = "default-tls")]
use hyper_tls::HttpsConnector;
#[cfg(all(feature = "default-tls", feature = "rustls-tls"))]
compile_error!("You must enable only one TLS implementation");
#[cfg(not(any(feature = "default-tls", feature = "rustls-tls")))]
compile_error!("You must enable at least one TLS implementation");

type HttpClient = hyper::Client<HttpsConnector<hyper::client::HttpConnector>, hyper::Body>;

pub type Response<T> = Pin<Box<dyn Future<Output = Result<T, Error>> + Send>>;

Expand Down Expand Up @@ -44,7 +52,7 @@ impl Client {
pub fn from_url(scheme_host: impl Into<String>, secret_key: impl Into<String>) -> Client {
let url = scheme_host.into();
let host = if url.ends_with('/') { format!("{}v1", url) } else { format!("{}/v1", url) };
let https = hyper_tls::HttpsConnector::new();
let https = HttpsConnector::new();
let client = hyper::Client::builder().build(https);
let mut headers = Headers::default();
// TODO: Automatically determine the latest supported api version in codegen?
Expand Down

0 comments on commit 3433cb1

Please sign in to comment.