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

System proxy seems doesn't work. #790

Closed
ramsayleung opened this issue Jan 19, 2020 · 8 comments · Fixed by #793
Closed

System proxy seems doesn't work. #790

ramsayleung opened this issue Jan 19, 2020 · 8 comments · Fixed by #793

Comments

@ramsayleung
Copy link

ramsayleung commented Jan 19, 2020

Hi Sean, thanks for your hard work, you build an awesome Http client. I have encountered a problem when I used system proxy with reqwest. The document claims reqwest doesn't need the explict system proxy setting, system proxies are enabled by default:

System proxies look in environment variables to set HTTP or HTTPS proxies.

HTTP_PROXY or http_proxy provide http proxies for http connections while HTTPS_PROXY or https_proxy provide HTTPS proxies for HTTPS connections.

What I struggle with is that I have explictly set the system proxy setting with:

export HTTPS_PROXY=socks5://127.0.0.1:2085

but reqwest still goes without proxy.

This is my code:

use std::env;
extern crate log;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    env_logger::init();
    match env::var("HTTPS_PROXY") {
        Ok(proxy) => println!("proxy: {}", proxy),
        Err(e) => println!("Couldn't read HTTPS_PROXY ({})", e),
    };
    let client = reqwest::blocking::Client::builder()
        .connection_verbose(true)
        .build()?;
    let mut res = client.get("https://httpbin.org/ip").send()?;
    // copy the response body directly to stdout
    res.copy_to(&mut std::io::stdout())?;
    Ok(())
}

This is the output:

$ RUST_LOG=reqwest=debug cargo run
   Compiling reqwest-test v0.1.0 (/private/tmp/reqwest-test)
    Finished dev [unoptimized + debuginfo] target(s) in 3.74s
     Running `target/debug/reqwest-test`
proxy: socks5://127.0.0.1:2085
[2020-01-19T08:05:15Z DEBUG reqwest::async_impl::response] Response: '200 OK' for https://httpbin.org/ip
{
  "origin": "ip1, ip2" // this is definitely not the ip of my proxy server
}

Do I do something wrong or miss something? I can't figure out why couldn't reqwest work with system proxy.

@WindSoilder
Copy link
Contributor

WindSoilder commented Jan 19, 2020

What I remember is that system proxy only support http scheme and https scheme for now. Others will be omitted..

@seanmonstar
Copy link
Owner

Oh ya, we probably need to add the socks support to the system proxy code.

@ramsayleung
Copy link
Author

Before I submit this issue, I have searched all issues of reqwest, I remember reqwest is supporting socks proxy now, #287, or reqwest supports both socks proxy and system proxy, but the system proxy doesn't support socks proxy?

@WindSoilder
Copy link
Contributor

WindSoilder commented Jan 20, 2020

I found that reqwest can use socks through http_proxy or https_proxy variable in my environment, sorry for yesterday's misleading information :(

I have seen your PR in rspotify, to use socks proxy, socks feature is required.

reqwest = { version = "0.10", features = ["blocking", "json", "socks"] }

@ramsayleung
Copy link
Author

ramsayleung commented Jan 20, 2020

Wow, it works now, I just simply omit this feature when I go through the document, thanks so much for pointing it out :)

@seanmonstar
Copy link
Owner

Ah, is there something we could have done to make that clearer? Do the proxy docs mention the socks feature? Should we log that socks was ignored since the feature wasn't enabled?

@WindSoilder
Copy link
Contributor

I think it's good enough to doc them in the lib :)

@ramsayleung
Copy link
Author

You guys do a great job to make reqwest better :)

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

Successfully merging a pull request may close this issue.

3 participants