Support creating a client with a custom tls connector#562
Support creating a client with a custom tls connector#562Goirad wants to merge 1 commit intoseanmonstar:masterfrom
Conversation
|
Thanks for the PR! Do you have some specific case that can't be solved by the existing config options? I'm wary of exposing such an API as it means that upgrade to a new version becomes a breaking change in reqwest. |
|
For example, setting |
|
I'd also like this feature. For example, I intend to add more advanced certificate validation options to |
|
The issue about not being able to upgrade versions internally seems important to me... Since reqwest can potentially use different TLS backends, it seems reasonable to me to provide TLS options as needed on the |
|
Not all configuration options are going to be available on all backends. Clearly, if someone wants to put in their own builder, they've already decided on a particular TLS backend. It's good to have sane & safe defaults for most users, but I think these are the options:
|
|
As I was curious how curl handles this, they have a An advanced option passing |
|
Do you need a callback? You could also do something like |
|
As an advanced config option, it allows users to decide what to do if the backend isn't what you wanted. Maybe you can set the advanced options in multiple backends. Maybe the advanced option wasn't critical, just a nice-to-have, and so you do nothing. Or you could choose to just panic... |
|
I think your proposal sounds very similar to this: impl ClientBuilder {
/// Returns `false` if `reqwest` doesn't know how to use the provided `connector`.
fn with_preconfigured_connector(&mut self, mut connector: impl Any) -> bool {
if let Some(conn) = connector.downcast_mut::<NativeTlsConnector>() {
self.connector = NativeTls(std::mem::replace(conn, Default::default()))
} else if ... {
...
} else {
return false
}
true
}
}I'd think I'd prefer a compilation error over something that will panic at runtime? I guess one could test for this if they needed it to work. But then I feel that should be clearly documented. |
5eaa295 to
33d407e
Compare
|
I have updated the PR to reflect Jethro's suggestion, and although it compiles I have not tested the new functionality, it is mostly just a proof of concept at this point. |
33d407e to
b0fe470
Compare
Ah, I didn't notice this was inverted to what I was thinking. My initial thoughts were to return |
b0fe470 to
20fa2c5
Compare
20fa2c5 to
8a3fc48
Compare
|
I continued this in #606 with some changes and tests. |
This PR would allow a user to create a client by supplying a
native-tls::TlsConnector, rather than just being able to specify eitherdefault-tlsorrustls.