1

I'm trying to use Reqwest's proxy feature to pass user:pass basic auth with the rest of the URL into the proxy function. Apparently, the way this crate works basic auth can't be passed this way for the proxy.

When I commented out proxy I got my data but it didn't go through my proxy:

let raw_proxy = format!("https://{}:{}@{}", username, password, forward_proxy);
let proxy = reqwest::Proxy::all(&raw_proxy).unwrap();
let mut buf = &mut Vec::new();

File::open("../cert.der").unwrap().read_to_end(&mut buf).unwrap();
let cert = reqwest::Certificate::from_der(&buf).unwrap();
let client = reqwest::Client::builder()
    .add_root_certificate(cert)
    //.proxy(proxy)
    .build().unwrap();

let mut res = client.post("http://httpbin.org/post")
    .header(ContentType::json())
    .body(format!("{}", redacted_data))
    .send().unwrap();
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Joe
  • 39
  • 7

2 Answers2

1

Short answer is you cannot without writing more code. For the longer answer see this ticket I opened 2 years back. https://github.com/hyperium/hyper/issues/531

Basically, authenticated proxies do not work currently. The headers are not being updated.

The author is supportive, it is just not a high priority. I stopped being behind a proxy so it stopped being one for me too.

Sean Perry
  • 3,776
  • 1
  • 19
  • 31
1

If you are using the latest reqwest version, this problem already solved. You need to make sure if your are using HTTP or HTTPS. To double check whether it's connecting to proxy or not, you can use tools like Burp.

I wrote the full-guide on how to setup and test proxy, self-signed certification and Burp for reqwest in here https://www.yodiw.com/rust-reqwest-via-proxy-and-ssl-certificate-captured-by-burp/

yodi
  • 942
  • 8
  • 10