Hyper: HTTPS Request: Invalid scheme for Http

Created on 16 Jan 2017  路  14Comments  路  Source: hyperium/hyper

I'm currently building against v0.10 and am experiencing some issues trying to send a request on macOS 10.12.

Here's a minimal example.

extern crate hyper;

use hyper::Client;
use hyper::Url;

fn main() {
    let url = "https://httpbin.org/get";

    let url = Url::parse(&url).unwrap();
    println!("{:?}", url);

    let client = Client::new();
    let res = client.get(url).send();
    println!("{:?}", res);
}
"https://httpbin.org/get"
Err(Io(Error { repr: Custom(Custom { kind: InvalidInput, error: StringError("Invalid scheme for Http") }) })

When I build against hyper = { version = "0.9", default-features = false, features = ["security-framework"] }this example runs just fine, so I'm guessing the issue has something to do with macOS' security-framework handling in hyper?

The error does not occur when requesting http://httpbin.org/get.

Most helpful comment

Just ran into this. A couple of suggestions:

  • The client guide buries this issue under "Client Configuration" which is several steps too late into the flow. Please make a point of calling out that an additional crate is required to do TLS.
  • Please consider breaking the TLS portion of "Client Configuration" into a separate "Enabling HTTPS" section to make this clearer to folks skimming docs.
  • Please make the error message more directive. This is bubbling up in my first client integration as Error { repr: Custom(Custom { kind: InvalidInput, error: NotHttp }) } which doesn't tell me very much about what is going on

All 14 comments

hyper no longer includes a default TLS library, so you'll need to pick one. I'd recommend hyper-native-tls.

See #985 for reasoning.

Ah, I see. Thanks for the link and reasoning!

Would it be possible to make the error messages a little more clear though than they currently are? I tried quite a bit to debug this and was unable to find out anything by looking around with the error message. It probably would've helped if I've looked in the issues here more closely, but a quick search didn't show anything 馃槙

I could certainly see value in adding a error!("HttpConnector used to connect to HTTPS URL, try using HttpsConnector with an SSL implementation") or similar just before returning the Err.

That would be great!

Of course, this would only alert you if you had some sort of logger setup...

Separately, I wonder if it makes sense to change from suggesting Client::new() to Client::http() (or even Client::plaintext()?), so it is explicit that the client won't be able to connect to HTTPS.

I guess the good news is that when I searched for http-1009 this was the 2nd entry in Google's results, and the first one I clicked on, so you accomplished making information available for others who need help.

Does this work with 0.11.0? It seems that hyper::net no longer exists.

Does this work with 0.11.0? It seems that hyper::net no longer exists.

This ^ im currently using 0.10 as hyper::net is gone. Any update on this..?

You can use hyper-tls. The guide explains how to use it with v0.11.

Just ran into this. A couple of suggestions:

  • The client guide buries this issue under "Client Configuration" which is several steps too late into the flow. Please make a point of calling out that an additional crate is required to do TLS.
  • Please consider breaking the TLS portion of "Client Configuration" into a separate "Enabling HTTPS" section to make this clearer to folks skimming docs.
  • Please make the error message more directive. This is bubbling up in my first client integration as Error { repr: Custom(Custom { kind: InvalidInput, error: NotHttp }) } which doesn't tell me very much about what is going on

Just ran into this. I copy and pasted the snippet from the client guide, and changed the URL to https scheme, boom. This is 2019, please look around: plain http is not used any more. As for your example, http://httpbin.org: if i enter "httpbin.org" into my browser URL, it will use https://httpbin.org.

By default, a Client can only speak to HTTP addresses. This is so last year. Compare to

By default, a Client can only speak to HTTPS addresses using TLS 1.3

https should be the default, and the #1 rust http client library that shows up on Google (via https) should support it out-of-the-box, or have a feature matrix as the first section that clearly states that https requires extra effort. I'm already prepared to find out hyper doesn't support proxies ;)

Why does this code still run into the error "invalid URL, scheme is not http".

Thx

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jswrenn picture jswrenn  路  44Comments

seanmonstar picture seanmonstar  路  48Comments

sfackler picture sfackler  路  23Comments

habnabit picture habnabit  路  20Comments

bagder picture bagder  路  32Comments