mirror of
https://git.proxmox.com/git/proxmox
synced 2025-10-04 08:36:31 +00:00
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 <c.ebner@proxmox.com>
This commit is contained in:
parent
64b2f082f5
commit
ca351ecf7e
@ -22,6 +22,7 @@ openssl = { version = "0.10", optional = true }
|
|||||||
serde_json = { workspace = true, optional = true }
|
serde_json = { workspace = true, optional = true }
|
||||||
tokio = { workspace = true, features = [], optional = true }
|
tokio = { workspace = true, features = [], optional = true }
|
||||||
tokio-openssl = { workspace = true, 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 }
|
ureq = { version = "2.4", features = ["native-certs", "native-tls"], optional = true, default-features = false }
|
||||||
url = { workspace = true, optional = true }
|
url = { workspace = true, optional = true }
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ use std::task::{Context, Poll};
|
|||||||
|
|
||||||
use futures::*;
|
use futures::*;
|
||||||
use http::Uri;
|
use http::Uri;
|
||||||
|
use hyper::client::connect::dns::{GaiResolver, Name};
|
||||||
use hyper::client::HttpConnector;
|
use hyper::client::HttpConnector;
|
||||||
use openssl::ssl::SslConnector;
|
use openssl::ssl::SslConnector;
|
||||||
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
|
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
|
||||||
@ -23,8 +24,8 @@ use crate::{RateLimitedStream, ShareableRateLimit};
|
|||||||
type SharedRateLimit = Arc<dyn ShareableRateLimit>;
|
type SharedRateLimit = Arc<dyn ShareableRateLimit>;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct HttpsConnector {
|
pub struct HttpsConnector<T = GaiResolver> {
|
||||||
connector: HttpConnector,
|
connector: HttpConnector<T>,
|
||||||
ssl_connector: Arc<SslConnector>,
|
ssl_connector: Arc<SslConnector>,
|
||||||
proxy: Option<ProxyConfig>,
|
proxy: Option<ProxyConfig>,
|
||||||
tcp_keepalive: u32,
|
tcp_keepalive: u32,
|
||||||
@ -32,9 +33,9 @@ pub struct HttpsConnector {
|
|||||||
write_limiter: Option<SharedRateLimit>,
|
write_limiter: Option<SharedRateLimit>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HttpsConnector {
|
impl<T> HttpsConnector<T> {
|
||||||
pub fn with_connector(
|
pub fn with_connector(
|
||||||
mut connector: HttpConnector,
|
mut connector: HttpConnector<T>,
|
||||||
ssl_connector: SslConnector,
|
ssl_connector: SslConnector,
|
||||||
tcp_keepalive: u32,
|
tcp_keepalive: u32,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@ -122,7 +123,13 @@ impl HttpsConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl hyper::service::Service<Uri> for HttpsConnector {
|
impl<T> hyper::service::Service<Uri> for HttpsConnector<T>
|
||||||
|
where
|
||||||
|
T: tower_service::Service<Name> + Clone + Send + Sync + 'static,
|
||||||
|
T::Future: Send,
|
||||||
|
T::Error: Into<Box<(dyn std::error::Error + Send + Sync + 'static)>>,
|
||||||
|
T::Response: std::iter::Iterator<Item = std::net::SocketAddr>,
|
||||||
|
{
|
||||||
type Response = MaybeTlsStream<RateLimitedStream<TcpStream>>;
|
type Response = MaybeTlsStream<RateLimitedStream<TcpStream>>;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
|
@ -8,6 +8,7 @@ use futures::*;
|
|||||||
#[cfg(all(feature = "client-trait", feature = "proxmox-async"))]
|
#[cfg(all(feature = "client-trait", feature = "proxmox-async"))]
|
||||||
use http::header::HeaderName;
|
use http::header::HeaderName;
|
||||||
use http::{HeaderValue, Request, Response};
|
use http::{HeaderValue, Request, Response};
|
||||||
|
use hyper::client::connect::dns::GaiResolver;
|
||||||
use hyper::client::Client as HyperClient;
|
use hyper::client::Client as HyperClient;
|
||||||
use hyper::client::HttpConnector;
|
use hyper::client::HttpConnector;
|
||||||
use hyper::Body;
|
use hyper::Body;
|
||||||
@ -18,7 +19,7 @@ use crate::HttpOptions;
|
|||||||
|
|
||||||
/// Asynchronous HTTP client implementation
|
/// Asynchronous HTTP client implementation
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
client: HyperClient<HttpsConnector, Body>,
|
client: HyperClient<HttpsConnector<GaiResolver>, Body>,
|
||||||
options: HttpOptions,
|
options: HttpOptions,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user