hyper-rustls 0.26 (#519)

* hyper-rustls 0.25

This isn't worth it until our dependencies update to rustls 0.22 as well.

* hyper-rustls 0.26 and hyper 1.0
This commit is contained in:
Luke Parker
2024-01-16 19:32:30 -05:00
committed by GitHub
parent 6691f16292
commit 9d3d47fc9f
5 changed files with 457 additions and 335 deletions

View File

@@ -5,14 +5,13 @@ use std::sync::Arc;
use tokio::sync::Mutex;
use tower_service::Service as TowerService;
#[cfg(feature = "tls")]
use hyper_rustls::{HttpsConnectorBuilder, HttpsConnector};
use hyper::{
Uri,
header::HeaderValue,
body::Body,
service::Service,
client::{HttpConnector, conn::http1::SendRequest},
use hyper::{Uri, header::HeaderValue, body::Bytes, client::conn::http1::SendRequest};
use hyper_util::{
rt::tokio::TokioExecutor,
client::legacy::{Client as HyperClient, connect::HttpConnector},
};
pub use hyper;
@@ -29,6 +28,7 @@ pub enum Error {
InconsistentHost,
ConnectionError(Box<dyn Send + Sync + std::error::Error>),
Hyper(hyper::Error),
HyperUtil(hyper_util::client::legacy::Error),
}
#[cfg(not(feature = "tls"))]
@@ -38,8 +38,12 @@ type Connector = HttpsConnector<HttpConnector>;
#[derive(Clone, Debug)]
enum Connection {
ConnectionPool(hyper::Client<Connector>),
Connection { connector: Connector, host: Uri, connection: Arc<Mutex<Option<SendRequest<Body>>>> },
ConnectionPool(HyperClient<Connector, Full<Bytes>>),
Connection {
connector: Connector,
host: Uri,
connection: Arc<Mutex<Option<SendRequest<Full<Bytes>>>>>,
},
}
#[derive(Clone, Debug)]
@@ -54,6 +58,7 @@ impl Client {
#[cfg(feature = "tls")]
let res = HttpsConnectorBuilder::new()
.with_native_roots()
.expect("couldn't fetch system's SSL roots")
.https_or_http()
.enable_http1()
.wrap_connector(res);
@@ -62,7 +67,9 @@ impl Client {
pub fn with_connection_pool() -> Client {
Client {
connection: Connection::ConnectionPool(hyper::Client::builder().build(Self::connector())),
connection: Connection::ConnectionPool(
HyperClient::builder(TokioExecutor::new()).build(Self::connector()),
),
}
}
@@ -115,7 +122,9 @@ impl Client {
}
let response = match &self.connection {
Connection::ConnectionPool(client) => client.request(request).await.map_err(Error::Hyper)?,
Connection::ConnectionPool(client) => {
client.request(request).await.map_err(Error::HyperUtil)?
}
Connection::Connection { connector, host, connection } => {
let mut connection_lock = connection.lock().await;