hyper-rustls icon indicating copy to clipboard operation
hyper-rustls copied to clipboard

confusion on `HttpsConnetor::wrap_connector`

Open niklasad1 opened this issue 2 years ago • 2 comments

Hey,

I thought the following would work to make https or http calls:


let mut connector = HttpConnector::new();
let connector = hyper_rustls::HttpsConnectorBuilder::new()
   .with_native_roots()
   .https_or_http()
   .enable_http1()
   .wrap_connector(connector),
		
let client = Client::builder().build::<_, hyper::Body>(connector);

but hyper reports back that https is not valid.

thread 'main' panicked at 'called Result::unwrap() on an Err value: Transport(HTTP error: error trying to connect: invalid URL, scheme is not http)'

niklasad1 avatar Apr 30 '22 07:04 niklasad1

Ah I see the entire connector config is used then I guess

niklasad1 avatar Apr 30 '22 07:04 niklasad1

I'm not sure what the issue is here, or if there was an issue in hyper-rustls at all. Is this actionable for us?

djc avatar May 10 '22 08:05 djc

Since the original poster hasn't replied with more detail I'm going to close this issue as unactionable for the time being. Thanks.

cpu avatar Mar 31 '23 17:03 cpu

Hey again.

Sorry forgot to answer and the issue was that the HttpConnector enforces the URI to be http and https is denied by default. Thus, the following fixes the panic:

let mut connector = HttpConnector::new();
connector.enforce_http(false);
let connector = hyper_rustls::HttpsConnectorBuilder::new()
   .with_native_roots()
   .https_or_http()
   .enable_http1()
   .wrap_connector(connector),
		
let client = Client::builder().build::<_, hyper::Body>(connector);

It's easy to get wrong and because this repo connector is a HTTPS, it would makes sense to me to set connector.enforce_http(false) in HttpsConnectorBuilder::wrap_connector to allow HTTPs URIs by default but since it's generic it's probably not possible.

niklasad1 avatar Dec 11 '23 09:12 niklasad1