diff --git a/CHANGELOG.md b/CHANGELOG.md index 92d5202..6a9e296 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ReleaseDate +### Added +- client: support HTTPS ([#54]). + ### Changed - query: improve throughput (~8%). @@ -14,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - cursor: handle errors sent at the end of a response ([#56]). [#56]: https://github.com/loyd/clickhouse.rs/issues/56 +[#54]: https://github.com/loyd/clickhouse.rs/pull/54 ## [0.11.2] - 2023-01-03 ### Added diff --git a/README.md b/README.md index 8661f4b..795c1d5 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ A typed client for ClickHouse. * Uses `serde` for encoding/decoding rows. * Uses `RowBinary` encoding. +* Supports HTTP and HTTPS. * Provides API for selecting. * Provides API for inserting. * Provides API for infinite transactional (see below) inserting. @@ -207,6 +208,7 @@ See [examples](https://github.com/loyd/clickhouse.rs/tree/master/examples). ## Feature Flags * `lz4` (enabled by default) — enables `Compression::Lz4` and `Compression::Lz4Hc(_)` variants. If enabled, `Compression::Lz4` is used by default for all queries except for `WATCH`. +* `tls` (enabled by default) — supports urls with the `HTTPS` schema. * `test-util` — adds mocks. See [the example](https://github.com/loyd/clickhouse.rs/tree/master/examples/mock.rs). Use it only in `dev-dependencies`. * `watch` — enables `client.watch` functionality. See the corresponding section for details. * `uuid` — adds `serde::uuid` to work with [uuid](https://docs.rs/uuid/latest/uuid/) crate. diff --git a/src/lib.rs b/src/lib.rs index b99c87a..3af1e77 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,6 @@ extern crate static_assertions; use std::{collections::HashMap, sync::Arc, time::Duration}; use hyper::client::connect::HttpConnector; - #[cfg(feature = "tls")] use hyper_tls::HttpsConnector; @@ -67,11 +66,15 @@ pub struct Client { impl Default for Client { fn default() -> Self { + #[allow(unused_mut)] let mut connector = HttpConnector::new(); // TODO: make configurable in `Client::builder()`. connector.set_keepalive(Some(TCP_KEEPALIVE)); + #[cfg(feature = "tls")] + let connector = HttpsConnector::new_with_connector(connector); + let client = hyper::Client::builder() .pool_idle_timeout(POOL_IDLE_TIMEOUT) .build(connector); @@ -104,16 +107,6 @@ impl Client { /// ``` pub fn with_url(mut self, url: impl Into) -> Self { self.url = url.into(); - - #[cfg(feature = "tls")] - if self.url.starts_with("https:") { - let mut connector = HttpsConnector::new(); - let client = hyper::Client::builder() - .pool_idle_timeout(POOL_IDLE_TIMEOUT) - .build::<_, hyper::Body>(connector); - self.client = Arc::new(client); - } - self }