Skip to content

Commit e783312

Browse files
committed
Merge pull request #324 from arlyon/webpki
Webpki
2 parents 99127a7 + 050471a commit e783312

File tree

7 files changed

+110
-21
lines changed

7 files changed

+110
-21
lines changed

.github/workflows/async-stripe.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ jobs:
5959
async-std-surf,
6060
tokio-hyper,
6161
tokio-hyper-rustls,
62+
tokio-hyper-rustls-webpki,
6263
blocking,
6364
blocking-rustls,
65+
blocking-rustls-webpki,
6466
]
6567
steps:
6668
- uses: actions/checkout@v2
@@ -93,8 +95,10 @@ jobs:
9395
async-std-surf,
9496
tokio-hyper,
9597
tokio-hyper-rustls,
98+
tokio-hyper-rustls-webpki,
9699
blocking,
97100
blocking-rustls,
101+
blocking-rustls-webpki,
98102
]
99103
services:
100104
stripe-mock:
@@ -115,7 +119,7 @@ jobs:
115119
~/.cargo/registry
116120
~/.cargo/git
117121
target
118-
key: ${{ runner.os }}-test-${{ hashFiles('**/Cargo.lock') }}
122+
key: ${{ runner.os }}-test-${{ matrix.runtime }}-${{ hashFiles('**/Cargo.lock') }}
119123
- uses: taiki-e/install-action@cargo-llvm-cov
120124
- name: Test and gather coverage
121125
run: cargo llvm-cov --lcov --output-path lcov.info --features runtime-${{ matrix.runtime }}

Cargo.toml

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,58 @@ events = []
6666
async = ["futures-util"]
6767
blocking = []
6868

69-
runtime-tokio-hyper = ["tokio", "hyper-client", "hyper-tls", "async"]
70-
runtime-tokio-hyper-rustls = ["tokio", "hyper-client", "hyper-rustls", "async"]
71-
runtime-blocking = ["tokio", "tokio/rt", "hyper-client", "hyper-tls", "blocking"]
69+
runtime-tokio-hyper = [
70+
"tokio",
71+
"hyper-client",
72+
"hyper-tls",
73+
"async",
74+
]
75+
runtime-tokio-hyper-rustls = [
76+
"tokio",
77+
"hyper-client",
78+
"hyper-rustls",
79+
"hyper-rustls-native",
80+
"async",
81+
]
82+
runtime-tokio-hyper-rustls-webpki = [
83+
"tokio",
84+
"hyper-client",
85+
"hyper-rustls-webpki",
86+
"async",
87+
]
88+
runtime-blocking = [
89+
"tokio",
90+
"tokio/rt",
91+
"hyper-client",
92+
"hyper-tls",
93+
"blocking",
94+
]
7295
runtime-blocking-rustls = [
73-
"tokio",
74-
"tokio/rt",
75-
"hyper-client",
76-
"hyper-rustls",
77-
"blocking",
96+
"tokio",
97+
"tokio/rt",
98+
"hyper-client",
99+
"hyper-rustls-native",
100+
"blocking",
101+
]
102+
runtime-blocking-rustls-webpki = [
103+
"tokio",
104+
"tokio/rt",
105+
"hyper-client",
106+
"hyper-rustls-webpki",
107+
"blocking",
108+
]
109+
runtime-async-std-surf = [
110+
"async-std",
111+
"surf",
112+
"async",
78113
]
79-
runtime-async-std-surf = ["async-std", "surf", "async"]
80114

81115
# we need the compat crate if using hyper
82116
hyper-client = ["hyper", "http-types/hyperium_http"]
83117

118+
hyper-rustls-native = ["hyper-rustls", "hyper-rustls/native-tokio"]
119+
hyper-rustls-webpki = ["hyper-rustls", "hyper-rustls/webpki-tokio"]
120+
84121
[dependencies]
85122
async-std = {version = "1.8,<1.11", optional = true}
86123

@@ -89,7 +126,7 @@ thiserror = "1.0.24"
89126
http-types = { version = "2.12.0", default-features = false }
90127
hyper = { version = "0.14", default-features = false, features = ["http1", "http2", "client", "tcp"], optional = true }
91128
hyper-tls = { version = "0.5", optional = true }
92-
hyper-rustls = { version = "0.22", optional = true }
129+
hyper-rustls = { version = "0.23", default-features = false, features = ["http1", "http2", "tls12", "logging"], optional = true }
93130
serde = {version = ">=1.0.79", features = ["derive"] } # we use `serde(other)` which was introduced in 1.0.79
94131
serde_json = "1.0"
95132
serde_qs = "0.10.1"
@@ -108,6 +145,8 @@ hmac = { version = "0.12", optional = true }
108145
sha2 = { version = "0.10", optional = true }
109146
hex = { version = "0.4", optional = true }
110147

148+
rocket = { version = "0.4", optional = true }
149+
111150
[dev-dependencies]
112151
async-std = { version = "1.10.0", features = ["attributes"] }
113152
httpmock = "0.6.6"
@@ -150,3 +189,7 @@ required-features = ["async"]
150189
[[example]]
151190
name = "webhook-actix"
152191
required-features = ["async"]
192+
193+
[[example]]
194+
name = "webhook-rocket"
195+
required-features = ["rocket"]

examples/checkout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ async fn main() {
6868

6969
// finally, create a checkout session for this product / price
7070
let checkout_session = {
71-
let mut params =
72-
CreateCheckoutSession::new("http://test.com/cancel", "http://test.com/success");
71+
let mut params = CreateCheckoutSession::new("http://test.com/success");
72+
params.cancel_url = Some("http://test.com/cancel");
7373
params.customer = Some(customer.id);
7474
params.mode = Some(CheckoutSessionMode::Payment);
7575
params.line_items = Some(vec![CreateCheckoutSessionLineItems {

src/client/base/async_std.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ async fn send_inner(
8686
Ok(response) => response,
8787
Err(err) => {
8888
last_error = StripeError::from(err);
89+
tries += 1;
8990
continue;
9091
}
9192
};

src/client/base/tokio.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,35 @@ use tokio::time::sleep;
1010
use crate::client::request_strategy::{Outcome, RequestStrategy};
1111
use crate::error::{ErrorResponse, StripeError};
1212

13-
#[cfg(feature = "hyper-rustls")]
13+
#[cfg(feature = "hyper-rustls-native")]
1414
mod connector {
1515
use hyper::client::{connect::dns::GaiResolver, HttpConnector};
1616
pub use hyper_rustls::HttpsConnector;
17+
use hyper_rustls::HttpsConnectorBuilder;
1718

1819
pub fn create() -> HttpsConnector<HttpConnector<GaiResolver>> {
19-
HttpsConnector::with_native_roots()
20+
HttpsConnectorBuilder::new()
21+
.with_native_roots()
22+
.https_or_http()
23+
.enable_http1()
24+
.enable_http2()
25+
.build()
26+
}
27+
}
28+
29+
#[cfg(feature = "hyper-rustls-webpki")]
30+
mod connector {
31+
use hyper::client::{connect::dns::GaiResolver, HttpConnector};
32+
pub use hyper_rustls::HttpsConnector;
33+
use hyper_rustls::HttpsConnectorBuilder;
34+
35+
pub fn create() -> HttpsConnector<HttpConnector<GaiResolver>> {
36+
HttpsConnectorBuilder::new()
37+
.with_webpki_roots()
38+
.https_or_http()
39+
.enable_http1()
40+
.enable_http2()
41+
.build()
2042
}
2143
}
2244

@@ -115,6 +137,7 @@ async fn send_inner(
115137
Ok(response) => response,
116138
Err(err) => {
117139
last_error = StripeError::from(err);
140+
tries += 1;
118141
continue;
119142
}
120143
};

src/client/mod.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,39 @@ mod base {
55
#[cfg(any(
66
feature = "runtime-tokio-hyper",
77
feature = "runtime-tokio-hyper-rustls",
8+
feature = "runtime-tokio-hyper-rustls-webpki",
89
feature = "runtime-blocking",
910
feature = "runtime-blocking-rustls",
11+
feature = "runtime-blocking-rustls-webpki",
1012
))]
1113
pub mod tokio;
1214

1315
#[cfg(feature = "runtime-async-std-surf")]
1416
pub mod async_std;
1517

16-
#[cfg(any(feature = "runtime-blocking", feature = "runtime-blocking-rustls"))]
18+
#[cfg(any(
19+
feature = "runtime-blocking",
20+
feature = "runtime-blocking-rustls",
21+
feature = "runtime-blocking-rustls-webpki"
22+
))]
1723
pub mod tokio_blocking;
1824
}
1925

20-
#[cfg(any(feature = "runtime-blocking", feature = "runtime-blocking-rustls"))]
26+
#[cfg(any(
27+
feature = "runtime-blocking",
28+
feature = "runtime-blocking-rustls",
29+
feature = "runtime-blocking-rustls-webpki"
30+
))]
2131
pub(crate) mod config {
2232
pub(crate) use super::base::tokio_blocking::{err, ok};
2333
pub use super::base::tokio_blocking::{Response, TokioBlockingClient as BaseClient};
2434
}
2535

26-
#[cfg(any(feature = "runtime-tokio-hyper", feature = "runtime-tokio-hyper-rustls"))]
36+
#[cfg(any(
37+
feature = "runtime-tokio-hyper",
38+
feature = "runtime-tokio-hyper-rustls",
39+
feature = "runtime-tokio-hyper-rustls-webpki"
40+
))]
2741
pub(crate) mod config {
2842
pub(crate) use super::base::tokio::{err, ok};
2943
pub use super::base::tokio::{Response, TokioClient as BaseClient};

src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,21 @@
4444
#[cfg(not(any(
4545
feature = "runtime-tokio-hyper",
4646
feature = "runtime-tokio-hyper-rustls",
47+
feature = "runtime-tokio-hyper-rustls-webpki",
4748
feature = "runtime-blocking",
4849
feature = "runtime-blocking-rustls",
50+
feature = "runtime-blocking-rustls-webpki",
4951
feature = "runtime-async-std-surf",
5052
)))]
5153
compile_error!(
5254
r"one of the following runtime features must be enabled:
5355
[
54-
'runtime-tokio-hyper',
56+
'runtime-tokio-hyper',
5557
'runtime-tokio-hyper-rustls',
56-
'runtime-blocking',
57-
'runtime-blocking-rustls',
58+
'runtime-tokio-hyper-rustls-webpki',
59+
'runtime-blocking',
60+
'runtime-blocking-rustls',
61+
'runtime-blocking-rustls-webpki',
5862
'runtime-async-std-surf'
5963
]"
6064
);

0 commit comments

Comments
 (0)