ClickHouse/clickhouse-rs

HTTPS url throws error

Closed this issue ยท 8 comments

I've looked into the PRs and https urls should work, but I'm still getting an error. Double checked that the tls feature is enabled:

Network(hyper::Error(Connect, "invalid URL, scheme is not http"))

This happens when executing a query:

let result = client.query("SELECT 1").fetch_one::<usize>().await.unwrap();

Am I doing something wrong or is this a bug?

I have the same error.
Looks like there need test with https.

eabz commented

I was facing the same issue and solved it using my own hyper server.

const POOL_IDLE_TIMEOUT: Duration = Duration::from_secs(2);

let https = HttpsConnector::new();

let client = hyper::Client::builder()
       .pool_idle_timeout(POOL_IDLE_TIMEOUT)
       .build::<_, hyper::Body>(https);

let db = Client::with_http_client(client)
       .with_url(db_host)
       .with_user(db_username)
       .with_password(db_password)
       .with_database(db_name);

Make sure you have the following depends:

hyper = "0.14" 
hyper-tls = "0.5"

@eabz used the same workaround for now, ty

ta3pks commented

I saw a pr merged like 2 years ago fixing this issue was it reverted for some reason ?

@eabz thanks a lot.

The issue seems to stem from the fact that HttpConnector.enforce_http is not set to false when the tls flag is enabled. I believe this is why @eabz 's workaround works (relevant source code in HttpsConnector::new)

loyd commented

It's a shame that this issue has existed for too long. It's better to have some fixes, even without checks in CI. I've created a dedicated issue for CI after spending half an hour trying to do it during this one.

Thanks to @MasterPtato for the direct tip. It seems to fix the problem.

My company doesn't use CH with HTTPs for now, so I'll be glad if someone can check this fix in an actual setup.

Another question is whether TLS error should have another variant in enum Error because it's an unrecoverable error.

loyd commented

Released in v0.11.6