Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for providing HttpConnector #254

Closed
dvaerum opened this issue Feb 8, 2024 · 3 comments
Closed

Add support for providing HttpConnector #254

dvaerum opened this issue Feb 8, 2024 · 3 comments

Comments

@dvaerum
Copy link

dvaerum commented Feb 8, 2024

Hey,

I want to ask if it would be possible to implement the HttpsConnector::new_with_connector which exists in the hyper_tls.
https://docs.rs/hyper-tls/latest/hyper_tls/struct.HttpsConnector.html#method.new_with_connector

I need it so that I can specific the network interface as shown in the example below

    let mut http_conn = HttpConnector::new();

    if let Some(network_interface) = network_interface {
        info!("Using network interface: {}", network_interface);
        http_conn.set_interface(network_interface);
    }

    let https_conn = HttpsConnector::new_with_connector(http_conn);

It may also be that there is a way to do this with hyper-rustls, but I have not found it

@djc
Copy link
Member

djc commented Feb 8, 2024

What is the problem you're trying to solve? You're proposing a potential solution (which I don't completely understand) but I'd like to understand what your use case is.

@ctz
Copy link
Member

ctz commented Feb 8, 2024

How about

let tls: hyper_rustls::HttpsConnector = ...;
HttpsConnector::from((http_conn, tls))

@dvaerum
Copy link
Author

dvaerum commented Feb 10, 2024

Hey @ctz
Your suggestion sadly did not work, keep getting the error

Error
the trait bound `Arc<rustls::client::client_conn::ClientConfig>: From<HttpsConnectorBuilder<WantsProtocols3>>` is not satisfied [E0277]
the trait `From<HttpsConnectorBuilder<WantsProtocols3>>` is not implemented for `Arc<rustls::client::client_conn::ClientConfig>`
Help: the following other types implement trait `From<T>`: <Arc<std::ffi::OsStr> as From<OsString>> <Arc<std::ffi::OsStr> as From<&std::ffi::OsStr>>
<Arc<Path> as From<PathBuf>>
<Arc<Path> as From<&Path>>
<Arc<CStr> as From<CString>>
<Arc<CStr> as From<&CStr>>
<Arc<str> as From<std::string::String>>
<Arc<str> as From<&str>> and 7 others
Note: required for `HttpsConnectorBuilder<WantsProtocols3>` to implement `Into<Arc<rustls::client::client_conn::ClientConfig>>`
Note: required for `hyper_rustls::HttpsConnector<HttpConnector>` to implement `From<(HttpConnector, HttpsConnectorBuilder<WantsProtocols3>)>`

But it did make me look one more time, and then I found the function/method I was looking for, called wrap_connector.

use log::info;
use hyper_util::client::legacy::connect::{HttpConnector};
use hyper_rustls;

pub(crate) fn get_https_connector(
    network_interface: Option<String>
) -> hyper_rustls::HttpsConnector<HttpConnector> {
    let mut http_conn = HttpConnector::new();

    if let Some(network_interface) = network_interface {
        info!("Using network interface: {}", network_interface);
        http_conn.set_interface(network_interface);
    }

    let tls = hyper_rustls::HttpsConnectorBuilder::new()
        .with_native_roots().expect("no native root CA certificates found")
        .https_or_http()
        .enable_all_versions();

    let https_conn = hyper_rustls::HttpsConnectorBuilder::new()
        .with_native_roots().expect("no native root CA certificates found")
        .https_or_http()
        .enable_all_versions().wrap_connector(http_conn);

    https_conn
}

@dvaerum dvaerum closed this as completed Feb 10, 2024
@djc djc reopened this Feb 10, 2024
@djc djc closed this as not planned Won't fix, can't repro, duplicate, stale Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants