Error when using IP address as the host
As mentioned in PR #32, minreq does not handle IP addresses in URLs properly right now. Sending the request via the basic HTTP backend seems to work, as well as https-native. I couldn't test the https-bundled-* features yet. So currently I'm assuming the problem only exists when using https-rustls.
How to reproduce
The following code (with the https-rustls feature enabled) prints the first print normally, as expected, but crashes on IoError(Custom { kind: Other, error: InvalidDNSNameError }) for the second one.
fn main() -> Result<(), minreq::Error> {
println!(
"GET https://httpbin.org/get: {:?}",
minreq::get("https://httpbin.org/get").send()?.as_str()
);
println!(
"GET https://34.194.129.11: {:?}",
minreq::get("https://34.194.129.11/get").send()?.as_str()
);
Ok(())
}
Note: the problem here is that the error is about the DNS, it should actually error out a little later because of the certificates: httpbin.org's certificates only apply for *.httpbin.org.
This is a small fix, I'll patch this at some point.
In #32, my thought process was like this;
Inside connection.rs, TcpStream::connect(&self.request.host) was happy with both dns_name or an ip, but https layer which in my case Rustls, was getting dns_name from &self.request.host and using it with ClientSession::new(&CONFIG, dns_name).
Because dns_name is an ip address it was rightfully giving an error of certificate domain name mismatch... To fix this and provide correct dns_name to Rustls ClientSession, I could either do a reverse DNS lookup to find out hostname from ip or use a hint, which in my case coming from request.headers "Host" element.
Currently I'm using my fix but when you get it fixed I'm going to use it gladly anyway :)
I tested this on a Linux system finally, and I can now confirm that the problem only occurs with the rustls backend. Unfortunately, it seems rustls does not support IP hostnames, because of briansmith/webpki#54. I'll periodically check the progress on rustls's side, and patch this when it's possible.
In the meantime, I'd try out one of the other https backends for when you really need to use an IP as the host, and in a case where there's a proper domain alternative, just go with that. I don't think automatic reverse DNS lookups are in-scope for this library.