Rust's hyper crate has a really irritating foot-gun
If you use the hyper crate, you may have run into the dreaded "invalid URL, scheme is not http" error. Digging into the docs, you may have found "By default, a Client can only speak to HTTP addresses. This is because hyper doesn't ship with a TLS implementation."
"No problem", you think, you follow their advice, cargo add hyper-tls
and build yourself an HttpsConnector
as they suggest. What if you want to customize the underlying connector, however? Something like:
let mut conn = HttpConnector::new(); conn.set_connect_timeout(conn_timeout.or(Some(Duration::from_secs(2)))); let client = hyper::Client::builder().build::<_, hyper::Body>(HttpsConnector::new_with_connector(conn)); client.get(hyper::Uri::from_static("https://crates.io"));
And yet… we still get "invalid URL, scheme is not http".
I finally found the answer in a years-old Github issue– HttpConnector
has an attribute, enforce_http
, which is set by default. Adding
conn.enforce_http(false);
to the above snippet got me going.