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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 457 additions and 335 deletions

741
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -17,11 +17,13 @@ rustdoc-args = ["--cfg", "docsrs"]
workspace = true workspace = true
[dependencies] [dependencies]
# Deprecated here means to enable deprecated warnings, not to restore deprecated APIs tower-service = { version = "0.3", default-features = false }
hyper = { version = "0.14", default-features = false, features = ["http1", "tcp", "client", "runtime", "backports", "deprecated"] } hyper = { version = "1", default-features = false, features = ["http1", "client"] }
hyper-util = { version = "0.1", default-features = false, features = ["http1", "client-legacy", "tokio"] }
http-body-util = { version = "0.1", default-features = false }
tokio = { version = "1", default-features = false } tokio = { version = "1", default-features = false }
hyper-rustls = { version = "0.24", default-features = false, features = ["http1", "native-tokio"], optional = true } hyper-rustls = { version = "0.26", default-features = false, features = ["http1", "ring", "rustls-native-certs", "native-tokio"], optional = true }
zeroize = { version = "1", optional = true } zeroize = { version = "1", optional = true }
base64ct = { version = "1", features = ["alloc"], optional = true } base64ct = { version = "1", features = ["alloc"], optional = true }

View file

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

View file

@ -1,12 +1,13 @@
use hyper::body::Body; use hyper::body::Bytes;
#[cfg(feature = "basic-auth")] #[cfg(feature = "basic-auth")]
use hyper::header::HeaderValue; use hyper::header::HeaderValue;
pub use http_body_util::Full;
#[cfg(feature = "basic-auth")] #[cfg(feature = "basic-auth")]
use crate::Error; use crate::Error;
#[derive(Debug)] #[derive(Debug)]
pub struct Request(pub(crate) hyper::Request<Body>); pub struct Request(pub(crate) hyper::Request<Full<Bytes>>);
impl Request { impl Request {
#[cfg(feature = "basic-auth")] #[cfg(feature = "basic-auth")]
fn username_password_from_uri(&self) -> Result<(String, String), Error> { fn username_password_from_uri(&self) -> Result<(String, String), Error> {
@ -59,8 +60,8 @@ impl Request {
let _ = self.basic_auth_from_uri(); let _ = self.basic_auth_from_uri();
} }
} }
impl From<hyper::Request<Body>> for Request { impl From<hyper::Request<Full<Bytes>>> for Request {
fn from(request: hyper::Request<Body>) -> Request { fn from(request: hyper::Request<Full<Bytes>>) -> Request {
Request(request) Request(request)
} }
} }

View file

@ -1,14 +1,15 @@
use hyper::{ use hyper::{
StatusCode, StatusCode,
header::{HeaderValue, HeaderMap}, header::{HeaderValue, HeaderMap},
body::{HttpBody, Buf, Body}, body::{Buf, Incoming},
}; };
use http_body_util::BodyExt;
use crate::{Client, Error}; use crate::{Client, Error};
// Borrows the client so its async task lives as long as this response exists. // Borrows the client so its async task lives as long as this response exists.
#[derive(Debug)] #[derive(Debug)]
pub struct Response<'a>(pub(crate) hyper::Response<Body>, pub(crate) &'a Client); pub struct Response<'a>(pub(crate) hyper::Response<Incoming>, pub(crate) &'a Client);
impl<'a> Response<'a> { impl<'a> Response<'a> {
pub fn status(&self) -> StatusCode { pub fn status(&self) -> StatusCode {
self.0.status() self.0.status()