hyperium / hyper-tls

Apache License 2.0
189 stars 96 forks source link

Is that possible to choose connector automatically? #20

Closed VikingMew closed 4 years ago

VikingMew commented 6 years ago

Hi, I tried to implement automatically choose connector based on given scheme. I tried.

  let client = match uri.scheme().unwrap(){
    "https" =>::hyper::Client::configure()
        .connector(::hyper_tls::HttpsConnector::new(4, &core.handle()).unwrap())
        .build(&core.handle()),
    _ =>  Client::new(&core.handle())
  };

but get

error[E0308]: match arms have incompatible types
  --> src\client.rs:50:16
   |
50 |     let client = match  uri.scheme().unwrap(){
   |  ________________^
51 | |     "https" =>::hyper::Client::configure()
52 | |         .connector(::hyper_tls::HttpsConnector::new(4, &core.handle()).unwrap())
53 | |         .build(&core.handle()),
54 | |     _ =>  Client::new(&core.handle())
   | |           --------------------------- match arm with an incompatible type
55 | |   };
   | |___^ expected struct `hyper_tls::HttpsConnector`, found struct `hyper::client::HttpConnector`
   |
   = note: expected type `hyper::Client<hyper_tls::HttpsConnector<hyper::client::HttpConnector>, _>`
              found type `hyper::Client<hyper::client::HttpConnector, _>`

is that possible to get a compatible type?

seanmonstar commented 6 years ago

Yea, that error is because the two clients are different types. The HttpsConnector in this crate already supports both schemes, only using TLS on HTTPS requests.

VikingMew commented 6 years ago

So I just need to create the HttpsConnector and it always works? Thanks.