Skip to content

Commit

Permalink
refactor: move support for HTTPS to the default contructor
Browse files Browse the repository at this point in the history
  • Loading branch information
loyd committed Feb 19, 2023
1 parent 37b7fea commit a74cc59
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<!-- next-header -->

## [Unreleased] - ReleaseDate
### Added
- client: support HTTPS ([#54]).

### Changed
- query: improve throughput (~8%).

### Fixed
- 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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 4 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -104,16 +107,6 @@ impl Client {
/// ```
pub fn with_url(mut self, url: impl Into<String>) -> 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
}

Expand Down

0 comments on commit a74cc59

Please sign in to comment.