Skip to content

Commit

Permalink
bump rust version, init crypto provider explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
blind-oracle committed Sep 4, 2024
1 parent fad1be7 commit 3efa7ce
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ jobs:
- run: cargo clippy --all-targets --no-default-features
- run: cargo build --all-targets --features native-tls
- run: cargo build --all-targets --features rustls-tls
- run: cargo build --all-targets --features rustls-tls-aws
- run: cargo clippy --all-targets --all-features

test:
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "MIT OR Apache-2.0"
readme = "README.md"
edition = "2021"
# update `derive/Cargo.toml` and CI if changed
rust-version = "1.67.0"
rust-version = "1.70.0"

[lints.rust]
rust_2018_idioms = { level = "warn", priority = -1 }
Expand Down Expand Up @@ -58,8 +58,8 @@ uuid = ["dep:uuid"]
time = ["dep:time"]
lz4 = ["dep:lz4_flex", "dep:cityhash-rs"]
native-tls = ["dep:hyper-tls"]
rustls-tls = ["dep:hyper-rustls", "hyper-rustls?/ring"]
rustls-tls-aws = ["dep:hyper-rustls", "hyper-rustls?/aws-lc-rs"]
rustls-tls = ["dep:hyper-rustls", "dep:rustls", "hyper-rustls?/ring"]
rustls-tls-aws = ["dep:hyper-rustls", "dep:rustls", "hyper-rustls?/aws-lc-rs"]

[dependencies]
clickhouse-derive = { version = "0.2.0", path = "derive" }
Expand All @@ -72,6 +72,7 @@ http-body-util = "0.1.2"
hyper = "1.4"
hyper-util = { version = "0.1.6", features = ["client-legacy", "http1"] }
hyper-tls = { version = "0.6.0", optional = true }
rustls = { version = "0.23", default-features = false, optional = true }
hyper-rustls = { version = "0.27.2", default-features = false, features = [
"http1",
"http2",
Expand Down
3 changes: 2 additions & 1 deletion derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ repository = "https://github.com/ClickHouse/clickhouse-rs"
homepage = "https://clickhouse.com"
edition = "2021"
license = "MIT OR Apache-2.0"
rust-version = "1.67.0" # update `Cargo.toml` and CI if changed
# update `Cargo.toml` and CI if changed
rust-version = "1.70.0"

[lib]
proc-macro = true
Expand Down
35 changes: 28 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ const TCP_KEEPALIVE: Duration = Duration::from_secs(60);
// See https://github.com/ClickHouse/ClickHouse/blob/368cb74b4d222dc5472a7f2177f6bb154ebae07a/programs/server/config.xml#L201
const POOL_IDLE_TIMEOUT: Duration = Duration::from_secs(2);

#[cfg(any(feature = "rustls-tls", feature = "rustls-tls-aws"))]
fn prepare_hyper_rustls_client(
connector: HttpConnector,
provider: impl Into<Arc<rustls::crypto::CryptoProvider>>,
) -> hyper_rustls::HttpsConnector<HttpConnector> {
hyper_rustls::HttpsConnectorBuilder::new()
.with_provider_and_webpki_roots(provider)
.unwrap()
.https_or_http()
.enable_http1()
.wrap_connector(connector)
}

/// A client containing HTTP pool.
#[derive(Clone)]
pub struct Client {
Expand All @@ -70,18 +83,26 @@ impl Default for Client {
// TODO: make configurable in `Client::builder()`.
connector.set_keepalive(Some(TCP_KEEPALIVE));

#[cfg(any(feature = "native-tls", feature = "rustls-tls"))]
#[cfg(any(
feature = "native-tls",
feature = "rustls-tls",
feature = "rustls-tls-aws"
))]
connector.enforce_http(false);

#[cfg(all(feature = "native-tls", not(feature = "rustls-tls")))]
#[cfg(all(
feature = "native-tls",
not(feature = "rustls-tls"),
not(feature = "rustls-tls-aws")
))]
let connector = hyper_tls::HttpsConnector::new_with_connector(connector);

#[cfg(feature = "rustls-tls")]
let connector = hyper_rustls::HttpsConnectorBuilder::new()
.with_webpki_roots()
.https_or_http()
.enable_http1()
.wrap_connector(connector);
let connector =
prepare_hyper_rustls_client(connector, rustls::crypto::ring::default_provider());
#[cfg(feature = "rustls-tls-aws")]
let connector =
prepare_hyper_rustls_client(connector, rustls::crypto::aws_lc_rs::default_provider());

let client = HyperClient::builder(TokioExecutor::new())
.pool_idle_timeout(POOL_IDLE_TIMEOUT)
Expand Down

0 comments on commit 3efa7ce

Please sign in to comment.