Repository: svix/svix-webhooks (language: rust)

Issue:
Feature request [rust]: allow specifying TLS flavour to use
## Feature Request

### Motivation

We are building our application against musl, cross-compiling it from regular libc Ubuntu. However, we are having issues with svix client, because it depends on system OpenSSL, which in our case would be linked against libc. There [are workarounds](https://github.com/sfackler/rust-openssl/issues/603), but they are a bit involved.

### Proposal
Allow user to choose whether `openssl` or `rustls` version of `reqwest` will be used by the svix client

### Alternatives

Alternative is to either vendor openssl, comiling it each time, or to use a pre-made Docker image with openssl compiled against musl included. However, we are already using reqwest with `rustls`, and would like to avoid having both flavours in the dependency tree, as well as extra complexity in the build pipeline.



Discussion / hints:
Thanks @msdinit! 

We actually explicitly switched away from rustls to openssl because it was causing issues. Take a look at #704, and let me know your thoughts.

> Use openssl instead of rusttls for outbound webhooks. In our experience,
many widely deployed webservers use "weak" ciphers that rusttls refuses to
support, leaving us with no choice but to rely on openssl libraries.
Ah, I see. Did not notice that as I only searched through the issues, not PRs :)

Regardless though, the PR you linked deals with the `server`, my request is about the [client](https://github.com/svix/svix-webhooks/blob/main/rust/Cargo.toml#L28).

Would you be open to having rustls as a non-default option for the client only? I _believe_ the overhead should be minimal (rename dependencies as `reqwest-openssl` and `reqwest-rustls` and conditionally importing from them, though would need to actually try it out)
Oh, sorry, I misread your request.

100%, we can easily change that, and potentially even make rustls the default. I didn't realize we were using openssl for that. Yeah, should be trivial.
Awesome, thank you!
The following patch seems that it does what is necessary, I have then ran three commands making sure the dependencies did or did not appear on the dependency tree as expected:
```
 # we have only the rustls-tls
 cargo tree --features rustls-tls --no-default-features

 # we have both since features are additive
 cargo tree --features rustls-tls

 # we have only default-tls
 cargo tree 
```

```
commit a212a162747e79cc6e814caa29764c15f9b0c65f
Author: Marcos <m...com>
Date:   Fri Apr 14 10:15:50 2023 +1000

    Feature request [rust]: allow specifying TLS flavour to use

    towards issue https://github.com/svix/svix-webhooks/issues/889

diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index a083cdd..bb118eb 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -25,5 +25,9 @@ serde = "^1.0"
 serde_derive = "^1.0"
 serde_json = "^1.0"
 url = "^2.2"
-reqwest = { version = "^0.11", features = ["json", "multipart", "default-tls"], default-features = false }
+reqwest = { version = "^0.11", features = ["json", "multipart"], default-features = false }
+
+[features]
+default = ["reqwest/default-tls"]
+rustls-tls = ["reqwest/rustls-tls"]
```
Oh awesome @marcoslopes, mind opening a PR? We would love to merge it.

Fix patch:
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index a083cdd6b..38ddc715f 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -25,5 +25,8 @@ serde = "^1.0"
 serde_derive = "^1.0"
 serde_json = "^1.0"
 url = "^2.2"
-reqwest = { version = "^0.11", features = ["json", "multipart", "default-tls"], default-features = false }
+reqwest = { version = "^0.11", features = ["json", "multipart"], default-features = false }
 
+[features]
+default = ["reqwest/default-tls"]
+rustls-tls = ["reqwest/rustls-tls"]
diff --git a/rust/README.md b/rust/README.md
index ac46eb868..b93073529 100644
--- a/rust/README.md
+++ b/rust/README.md
@@ -44,3 +44,15 @@ You can find general usage documentation at <https://docs.svix.com>.  For comple
 
 ## Usage
 Please refer to [the documentation](https://docs.svix.com/) or [the API reference](https://api.svix.com/docs) for more usage instructions.
+
+# Optional Cargo Features
+
+## TLS
+
+By default reqwest uses rust-native-tls, which will use the operating system TLS framework if available, meaning Windows and macOS. On Linux, it will use OpenSSL 1.1.
+
+[rustls-tls](https://github.com/rustls/rustls) can also be choosen, eg.:
+```
+svix = { version = "N", features = ["rustls-tls"], default-features = false  }
+```
+


Test patch: