Search code examples
sslhttpsrusthyper

Hyper says "Invalid scheme for Http" for HTTPS URLs


I have

hyper = "0.10"

And the following code:

let client = Client::new();
let mut res = client.get("https://google.com").send().unwrap();

Rust gives me the error message, as if it doesn't have SSL support:

Invalid scheme for Http

This is on Rust 1.14.0 on Debian jessie.

How do I get Hyper to connect with SSL to an HTTPS URL?


Solution

  • Try this:

    extern crate hyper;
    extern crate hyper_native_tls;
    
    use hyper::Client;
    use hyper::net::HttpsConnector;
    use hyper_native_tls::NativeTlsClient;
    
    fn main() {
        let ssl = NativeTlsClient::new().unwrap();
        let connector = HttpsConnector::new(ssl);
        let client = Client::with_connector(connector);
        let mut res = client.get("https://google.com").send().unwrap();
    }
    

    Mostly taken from this answer. What was missing was the Client::with_connector piece.