ferristseng / rust-ipfs-api

IPFS HTTP client in Rust
Apache License 2.0
246 stars 68 forks source link

Connection fails with rustls #106

Closed tmpfs closed 1 year ago

tmpfs commented 1 year ago

I am getting this error message trying to connect to an IPFS node over HTTPS using the with-hyper-rustls feature:

hyper client error `error trying to connect: invalid URL, scheme is not http`

The dependency is:

ipfs-api-backend-hyper = { version = "0.5", features = ["with-send-sync", "with-hyper-rustls"] }

I am using build_with_base_uri() from the TryFromUri trait. For example:

let client = IpfsClient::build_with_base_uri(uri);

Where uri is https://localhost.

Note that I want to pass in a custom URI and not use ~/.ipfs/api or the default URI.

Running a local daemon using ipfs daemon and a simple reverse proxy using caddy:

ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["https://localhost", "http://localhost:3000", "http://127.0.0.1:5001", "https://webui.ipfs.io"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "POST"]'
caddy reverse-proxy --to 127.0.0.1:5001

I can see IPFS working correctly by browsing to https://localhost/webui.

Any idea where the problem is or how I can use a custom URI with HTTPS?

tmpfs commented 1 year ago

My bad, I needed to be explicit with the generics. This works for me:

IpfsClient::<HttpsConnector<HttpConnector>>::from_host_and_port(scheme, host, port)?

Interestingly, build_with_base_uri() never seems to work (HTTP or HTTPS), I always get this error:

api returned an unknown error