Skip to content

Commit 9a08144

Browse files
authored
Add h1-client-rustls feature (#88)
* Add h1-client-rustls feature * Update README part in lib.rs * Remove test of wasm-client feature (requires wasm-pack) * Replaced localhost with 127.0.0.1 in tests (workaround for Github actions) * Fix typo
1 parent 1950876 commit 9a08144

File tree

6 files changed

+70
-14
lines changed

6 files changed

+70
-14
lines changed

Diff for: .github/workflows/rust.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ jobs:
4848
integration_test:
4949
name: Integration Tests (stable/ubuntu-latest)
5050
runs-on: ubuntu-latest
51+
strategy:
52+
matrix:
53+
http-backend: [curl-client, h1-client, h1-client-rustls, hyper-client]
5154
services:
5255
influxdb:
5356
image: influxdb:1.8
@@ -67,7 +70,7 @@ jobs:
6770
steps:
6871
- uses: actions/checkout@v1
6972
- uses: dtolnay/rust-toolchain@stable
70-
- run: cargo test --package influxdb --package influxdb_derive --all-features --no-fail-fast
73+
- run: cargo test --manifest-path=./influxdb/Cargo.toml --no-default-features --features 'use-serde derive ${{ matrix.http-backend }}' --no-fail-fast
7174

7275
coverage:
7376
name: Code Coverage (stable/ubuntu-20.04)

Diff for: README.md

+26
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Pull requests are always welcome. See [Contributing](https://github.com/Empty2k1
4545
- `#[derive(InfluxDbWriteable)]` Derive Macro for Writing / Reading into Structs
4646
- `GROUP BY` support
4747
- Tokio and async-std support (see example below) or [available backends](https://github.com/Empty2k12/influxdb-rust/blob/master/influxdb/Cargo.toml)
48+
- Swappable HTTP backends ([see below](#Choice-of-HTTP-backend))
4849

4950
## Quickstart
5051

@@ -98,6 +99,31 @@ async fn main() {
9899
For further examples, check out the Integration Tests in `tests/integration_tests.rs`
99100
in the repository.
100101

102+
## Choice of HTTP backend
103+
104+
To communicate with InfluxDB, you can choose the HTTP backend to be used configuring the appropriate feature:
105+
106+
- **[hyper](https://github.com/hyperium/hyper)** (used by default)
107+
```toml
108+
influxdb = { version = "0.3.0", features = ["derive"] }
109+
```
110+
- **[curl](https://github.com/alexcrichton/curl-rust)**, using [libcurl](https://curl.se/libcurl/)
111+
```toml
112+
influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "curl-client"] }
113+
```
114+
- **[async-h1](https://github.com/http-rs/async-h1)** with native TLS (OpenSSL)
115+
```toml
116+
influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "h1-client"] }
117+
```
118+
- **[async-h1](https://github.com/http-rs/async-h1)** with [rustls](https://github.com/ctz/rustls)
119+
```toml
120+
influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "h1-client-rustls"] }
121+
```
122+
- WebAssembly's `window.fetch`, via `web-sys` and **[wasm-bindgen](https://github.com/rustwasm/wasm-bindgen)**
123+
```toml
124+
influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "wasm-client"] }
125+
```
126+
101127
## License
102128

103129
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Diff for: influxdb/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ futures = "0.3.4"
2121
lazy_static = "1.4.0"
2222
influxdb_derive = { version = "0.3.0", optional = true }
2323
regex = "1.3.5"
24-
surf = { version = "2.1.0", default-features = false }
24+
surf = { version = "2.2.0", default-features = false }
2525
serde = { version = "1.0.104", features = ["derive"], optional = true }
2626
serde_json = { version = "1.0.48", optional = true }
2727
thiserror = "1.0"
@@ -30,6 +30,7 @@ thiserror = "1.0"
3030
use-serde = ["serde", "serde_json"]
3131
curl-client = ["surf/curl-client"]
3232
h1-client = ["surf/h1-client"]
33+
h1-client-rustls = ["surf/h1-client-rustls"]
3334
hyper-client = ["surf/hyper-client"]
3435
wasm-client = ["surf/wasm-client"]
3536
default = ["use-serde", "hyper-client"]

Diff for: influxdb/src/lib.rs

+26
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//! - `#[derive(InfluxDbWriteable)]` Derive Macro for Writing / Reading into Structs
1414
//! - `GROUP BY` support
1515
//! - Tokio and async-std support (see example below) or [available backends](https://github.com/Empty2k12/influxdb-rust/blob/master/influxdb/Cargo.toml)
16+
//! - Swappable HTTP backends ([see below](#Choice-of-HTTP-backend))
1617
//!
1718
//! # Quickstart
1819
//!
@@ -66,6 +67,31 @@
6667
//! For further examples, check out the Integration Tests in `tests/integration_tests.rs`
6768
//! in the repository.
6869
//!
70+
//! # Choice of HTTP backend
71+
//!
72+
//! To communicate with InfluxDB, you can choose the HTTP backend to be used configuring the appropriate feature:
73+
//!
74+
//! - **[hyper](https://github.com/hyperium/hyper)** (used by default)
75+
//! ```toml
76+
//! influxdb = { version = "0.3.0", features = ["derive"] }
77+
//! ```
78+
//! - **[curl](https://github.com/alexcrichton/curl-rust)**, using [libcurl](https://curl.se/libcurl/)
79+
//! ```toml
80+
//! influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "curl-client"] }
81+
//! ```
82+
//! - **[async-h1](https://github.com/http-rs/async-h1)** with native TLS (OpenSSL)
83+
//! ```toml
84+
//! influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "h1-client"] }
85+
//! ```
86+
//! - **[async-h1](https://github.com/http-rs/async-h1)** with [rustls](https://github.com/ctz/rustls)
87+
//! ```toml
88+
//! influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "h1-client-rustls"] }
89+
//! ```
90+
//! - WebAssembly's `window.fetch`, via `web-sys` and **[wasm-bindgen](https://github.com/rustwasm/wasm-bindgen)**
91+
//! ```toml
92+
//! influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "wasm-client"] }
93+
//! ```
94+
//!
6995
//! # License
7096
//!
7197
//! [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Diff for: influxdb/tests/integration_tests.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async fn test_ping_influx_db_tokio() {
5151
async fn test_connection_error() {
5252
let test_name = "test_connection_error";
5353
let client =
54-
Client::new("http://localhost:10086", test_name).with_auth("nopriv_user", "password");
54+
Client::new("http://127.0.0.1:10086", test_name).with_auth("nopriv_user", "password");
5555
let read_query = Query::raw_read_query("SELECT * FROM weather");
5656
let read_result = client.query(&read_query).await;
5757
assert_result_err(&read_result);
@@ -75,15 +75,15 @@ async fn test_authed_write_and_read() {
7575
run_test(
7676
|| async move {
7777
let client =
78-
Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password");
78+
Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password");
7979
let query = format!("CREATE DATABASE {}", TEST_NAME);
8080
client
8181
.query(&Query::raw_read_query(query))
8282
.await
8383
.expect("could not setup db");
8484

8585
let client =
86-
Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password");
86+
Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password");
8787
let write_query = Timestamp::Hours(11)
8888
.into_query("weather")
8989
.add_field("temperature", 82);
@@ -100,7 +100,7 @@ async fn test_authed_write_and_read() {
100100
},
101101
|| async move {
102102
let client =
103-
Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password");
103+
Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password");
104104
let query = format!("DROP DATABASE {}", TEST_NAME);
105105

106106
client
@@ -123,15 +123,15 @@ async fn test_wrong_authed_write_and_read() {
123123
run_test(
124124
|| async move {
125125
let client =
126-
Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password");
126+
Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password");
127127
let query = format!("CREATE DATABASE {}", TEST_NAME);
128128
client
129129
.query(&Query::raw_read_query(query))
130130
.await
131131
.expect("could not setup db");
132132

133133
let client =
134-
Client::new("http://localhost:9086", TEST_NAME).with_auth("wrong_user", "password");
134+
Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("wrong_user", "password");
135135
let write_query = Timestamp::Hours(11)
136136
.into_query("weather")
137137
.add_field("temperature", 82);
@@ -156,7 +156,7 @@ async fn test_wrong_authed_write_and_read() {
156156
),
157157
}
158158

159-
let client = Client::new("http://localhost:9086", TEST_NAME)
159+
let client = Client::new("http://127.0.0.1:9086", TEST_NAME)
160160
.with_auth("nopriv_user", "password");
161161
let read_query = Query::raw_read_query("SELECT * FROM weather");
162162
let read_result = client.query(&read_query).await;
@@ -171,7 +171,7 @@ async fn test_wrong_authed_write_and_read() {
171171
},
172172
|| async move {
173173
let client =
174-
Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password");
174+
Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password");
175175
let query = format!("DROP DATABASE {}", TEST_NAME);
176176
client
177177
.query(&Query::raw_read_query(query))
@@ -193,13 +193,13 @@ async fn test_non_authed_write_and_read() {
193193
run_test(
194194
|| async move {
195195
let client =
196-
Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password");
196+
Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password");
197197
let query = format!("CREATE DATABASE {}", TEST_NAME);
198198
client
199199
.query(&Query::raw_read_query(query))
200200
.await
201201
.expect("could not setup db");
202-
let non_authed_client = Client::new("http://localhost:9086", TEST_NAME);
202+
let non_authed_client = Client::new("http://127.0.0.1:9086", TEST_NAME);
203203
let write_query = Timestamp::Hours(11)
204204
.into_query("weather")
205205
.add_field("temperature", 82);
@@ -226,7 +226,7 @@ async fn test_non_authed_write_and_read() {
226226
},
227227
|| async move {
228228
let client =
229-
Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password");
229+
Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password");
230230
let query = format!("DROP DATABASE {}", TEST_NAME);
231231
client
232232
.query(&Query::raw_read_query(query))

Diff for: influxdb/tests/utilities.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn create_client<T>(db_name: T) -> Client
1818
where
1919
T: Into<String>,
2020
{
21-
Client::new("http://localhost:8086", db_name)
21+
Client::new("http://127.0.0.1:8086", db_name)
2222
}
2323

2424
#[cfg(not(tarpaulin_include))]

0 commit comments

Comments
 (0)