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

Connect through a proxy if environment variables are set. #369

Closed
ulrichard opened this issue Aug 20, 2020 · 4 comments · Fixed by #370
Closed

Connect through a proxy if environment variables are set. #369

ulrichard opened this issue Aug 20, 2020 · 4 comments · Fixed by #370

Comments

@ulrichard
Copy link

It would be nice, if a connection was established through proxies as specified in the env vars: http_proxy, https_proxy, HTTP_PROXY or HTTPS_PROXY
It looks like hyper has support for it, but requires the client to read the env vars.

@whizsid
Copy link
Contributor

whizsid commented Aug 24, 2020

I would like to work on this feature.

@tomusdrw
Copy link
Owner

@whizsid
Copy link
Contributor

whizsid commented Aug 24, 2020

@tomusdrw I took another approach. But I would like to accept your suggestions.

#[cfg(feature = "http-tls")]
#[derive(Debug, Clone)]
enum Client {
    Proxy(hyper::Client<hyper_proxy::ProxyConnector<hyper_tls::HttpsConnector<hyper::client::HttpConnector>>>),
    NoProxy(hyper::Client<hyper_tls::HttpsConnector<hyper::client::HttpConnector>>),
}

#[cfg(not(feature = "http-tls"))]
#[derive(Debug, Clone)]
enum Client {
    Proxy(hyper::Client<hyper_proxy::ProxyConnector<hyper::clinet::HttpConnector>>),
    NoProxy(hyper::Client<hyper::client::HttpConnector>),
}

impl Client {
    pub fn request(&self, req: hyper::Request<hyper::Body>) -> hyper::client::ResponseFuture {
        match self {
            Client::Proxy(client) => client.request(req),
            Client::NoProxy(client) => client.request(req),
        }
    }
}

May I continue with this approach? or with the above example?

@tomusdrw
Copy link
Owner

@whizsid Yup, looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants