Skip to content

Commit

Permalink
Adding default-tls and rustls-tls features (#44)
Browse files Browse the repository at this point in the history
* WIP creting rustls feature to replace OpenSSL

* edited README.md to reflect the new feature available on the crate

* implementing some validation to avoid enabling default-tls and rustls-tls feature

* ensuring that rustls-tls its used when feature is enabled

* Little tweaks

---------

Co-authored-by: Celeo <[email protected]>
  • Loading branch information
rafaga and Celeo authored Jul 17, 2024
1 parent 90fd1af commit 6001b83
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ http = "1.1.0"
jsonwebtoken = { version = "9.1.0", optional = true }
log = "0.4.20"
rand = "0.8.5"
reqwest = { version = "0.12.5", features = ["json"] }
reqwest = { version = "0.12.5", default-features = false, features = ["json", "charset", "http2", "macos-system-configuration"] }
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107"
sha2 = "0.10.8"
Expand All @@ -33,6 +33,8 @@ chrono = "0.4.31"
uuid = { version = "1.5.0", features = ["v4", "fast-rng"] }

[features]
default = ["random_state", "validate_jwt"]
default = ["random_state", "validate_jwt", "default-tls"]
random_state = []
validate_jwt = ["dep:jsonwebtoken"]
default-tls = ["reqwest/default-tls"]
rustls-tls = ["reqwest/rustls-tls"]
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Add the latest version to your `Cargo.toml`.

This crate has several features that are enabled by default.

If you don't want or need random SSO state string generation, you can disable the "random_state" feature.

If you don't want or need SSO token verification, you can disable the "validate_jwt" feature.
- If you don't want or need random SSO state string generation, you can disable the "random_state" feature.
- If you don't want or need SSO token verification, you can disable the "validate_jwt" feature.
- If you prefer to use [rustls](https://crates.io/crates/rustls) instead of your system's TLS implementation ([more info here](https://docs.rs/reqwest/latest/reqwest/tls/)) to make requests, you can disable the default features and add the "rustls-tls" feature.

## Using

Expand Down
8 changes: 8 additions & 0 deletions src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,18 @@ impl EsiBuilder {
);
map
};
#[cfg(not(feature = "rustls-tls"))]
let client = Client::builder()
.timeout(http_timeout)
.default_headers(headers)
.build()?;

#[cfg(feature = "rustls-tls")]
let client = Client::builder()
.timeout(http_timeout)
.default_headers(headers)
.use_rustls_tls()
.build()?;
Ok(client)
}

Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@
#![deny(clippy::all)]
#![deny(missing_docs)]

#[cfg(all(feature = "default-tls", feature = "rustls-tls"))]
compile_error!(
"feature \"default-tls\" and feature \"rustls-tls\" cannot be enabled at the same time"
);

#[macro_use]
mod macros;

Expand Down

0 comments on commit 6001b83

Please sign in to comment.