Reqwest: System proxy seems doesn't work.

Created on 19 Jan 2020  路  8Comments  路  Source: seanmonstar/reqwest

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.

Most helpful comment

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

All 8 comments

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

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

Before I submit this issue, I have searched all issues of reqwest, I remember reqwest is supporting socks proxy now, https://github.com/seanmonstar/reqwest/issues/287, or reqwest supports both socks proxy and system proxy, but the system proxy doesn't support socks proxy?

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"] }

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

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?

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

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

Was this page helpful?
0 / 5 - 0 ratings