salvo-rs / salvo

A powerful web framework built with a simplified design.
https://salvo.rs
Apache License 2.0
3.41k stars 208 forks source link

Self-signed certificate for proxy upstreams client #569

Closed AdrienPensart closed 10 months ago

AdrienPensart commented 11 months ago

Hello!

I try to give a client which would not check certificate validity for Proxy object, but can't manage to initialize it correctly, I tried with rustls, hyper-rustls, openssl, native-tls... no client or https connector seems to satisfy salvo::salvo_proxy::Client.

Do you have an clear example ? Do I have to implement some traits myself?

Thank you

chrislearn commented 11 months ago

Salvo use hyper-tls, refer to https://github.com/hyperium/hyper-tls/issues/11

AdrienPensart commented 10 months ago

Found solution!

let mut http_connector = HttpConnector::new();
http_connector.enforce_http(false);

let native_tls_connector = native_tls::TlsConnector::builder()
    .danger_accept_invalid_certs(true)
    .build()?;

let tls_connector = tokio_native_tls::TlsConnector::from(native_tls_connector);
let connector = HttpsConnector::from((http_connector, tls_connector));
let upstreams = ["https://localhost:5656/db/edgedb/edgeql"];
let proxy = Proxy::new(
    upstreams,
    HyperClient::new(
         HyperUtilClient::builder(salvo::rt::tokio::TokioExecutor::new()).build(connector),
    ),
);