From ca351ecf7ee062f531cb27357bd8d4f2d64d6c55 Mon Sep 17 00:00:00 2001 From: Christian Ebner Date: Wed, 9 Apr 2025 13:05:15 +0200 Subject: [PATCH] http: client: make https connector generic over resolver Allow to instantiate a `HttpsConnector` not using the default `getaddrinfo` based `GaiResolver` for domain name resolution, but rather a custom resolver implementing the required traits. The usecase for this is to swap out the DNS resolver for the statically linked proxmox-backup-client binary, where the glibc dependency is problematic because of possible ABI incompatibility. However, set the generic type on `HttpsConnector` to default to `GaiResolver` to limit inconvenience for implementations using it. Adds tower-service as cargo workspace dependency and build dependency to debian/control. Signed-off-by: Christian Ebner --- proxmox-http/Cargo.toml | 1 + proxmox-http/src/client/connector.rs | 17 ++++++++++++----- proxmox-http/src/client/simple.rs | 3 ++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/proxmox-http/Cargo.toml b/proxmox-http/Cargo.toml index c8c963f7..6bfb1413 100644 --- a/proxmox-http/Cargo.toml +++ b/proxmox-http/Cargo.toml @@ -22,6 +22,7 @@ openssl = { version = "0.10", optional = true } serde_json = { workspace = true, optional = true } tokio = { workspace = true, features = [], optional = true } tokio-openssl = { workspace = true, optional = true } +tower-service.workspace = true ureq = { version = "2.4", features = ["native-certs", "native-tls"], optional = true, default-features = false } url = { workspace = true, optional = true } diff --git a/proxmox-http/src/client/connector.rs b/proxmox-http/src/client/connector.rs index 63b9d10c..2e04680f 100644 --- a/proxmox-http/src/client/connector.rs +++ b/proxmox-http/src/client/connector.rs @@ -6,6 +6,7 @@ use std::task::{Context, Poll}; use futures::*; use http::Uri; +use hyper::client::connect::dns::{GaiResolver, Name}; use hyper::client::HttpConnector; use openssl::ssl::SslConnector; use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; @@ -23,8 +24,8 @@ use crate::{RateLimitedStream, ShareableRateLimit}; type SharedRateLimit = Arc; #[derive(Clone)] -pub struct HttpsConnector { - connector: HttpConnector, +pub struct HttpsConnector { + connector: HttpConnector, ssl_connector: Arc, proxy: Option, tcp_keepalive: u32, @@ -32,9 +33,9 @@ pub struct HttpsConnector { write_limiter: Option, } -impl HttpsConnector { +impl HttpsConnector { pub fn with_connector( - mut connector: HttpConnector, + mut connector: HttpConnector, ssl_connector: SslConnector, tcp_keepalive: u32, ) -> Self { @@ -122,7 +123,13 @@ impl HttpsConnector { } } -impl hyper::service::Service for HttpsConnector { +impl hyper::service::Service for HttpsConnector +where + T: tower_service::Service + Clone + Send + Sync + 'static, + T::Future: Send, + T::Error: Into>, + T::Response: std::iter::Iterator, +{ type Response = MaybeTlsStream>; type Error = Error; #[allow(clippy::type_complexity)] diff --git a/proxmox-http/src/client/simple.rs b/proxmox-http/src/client/simple.rs index 062889ac..cb8bb777 100644 --- a/proxmox-http/src/client/simple.rs +++ b/proxmox-http/src/client/simple.rs @@ -8,6 +8,7 @@ use futures::*; #[cfg(all(feature = "client-trait", feature = "proxmox-async"))] use http::header::HeaderName; use http::{HeaderValue, Request, Response}; +use hyper::client::connect::dns::GaiResolver; use hyper::client::Client as HyperClient; use hyper::client::HttpConnector; use hyper::Body; @@ -18,7 +19,7 @@ use crate::HttpOptions; /// Asynchronous HTTP client implementation pub struct Client { - client: HyperClient, + client: HyperClient, Body>, options: HttpOptions, }