mirror of
https://github.com/serai-dex/serai.git
synced 2024-11-16 17:07:35 +00:00
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:
parent
6691f16292
commit
9d3d47fc9f
5 changed files with 457 additions and 335 deletions
741
Cargo.lock
generated
741
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -17,11 +17,13 @@ rustdoc-args = ["--cfg", "docsrs"]
|
|||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
# Deprecated here means to enable deprecated warnings, not to restore deprecated APIs
|
||||
hyper = { version = "0.14", default-features = false, features = ["http1", "tcp", "client", "runtime", "backports", "deprecated"] }
|
||||
tower-service = { version = "0.3", default-features = false }
|
||||
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 }
|
||||
|
||||
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 }
|
||||
base64ct = { version = "1", features = ["alloc"], optional = true }
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
use hyper::body::Body;
|
||||
use hyper::body::Bytes;
|
||||
#[cfg(feature = "basic-auth")]
|
||||
use hyper::header::HeaderValue;
|
||||
pub use http_body_util::Full;
|
||||
|
||||
#[cfg(feature = "basic-auth")]
|
||||
use crate::Error;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Request(pub(crate) hyper::Request<Body>);
|
||||
pub struct Request(pub(crate) hyper::Request<Full<Bytes>>);
|
||||
impl Request {
|
||||
#[cfg(feature = "basic-auth")]
|
||||
fn username_password_from_uri(&self) -> Result<(String, String), Error> {
|
||||
|
@ -59,8 +60,8 @@ impl Request {
|
|||
let _ = self.basic_auth_from_uri();
|
||||
}
|
||||
}
|
||||
impl From<hyper::Request<Body>> for Request {
|
||||
fn from(request: hyper::Request<Body>) -> Request {
|
||||
impl From<hyper::Request<Full<Bytes>>> for Request {
|
||||
fn from(request: hyper::Request<Full<Bytes>>) -> Request {
|
||||
Request(request)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
use hyper::{
|
||||
StatusCode,
|
||||
header::{HeaderValue, HeaderMap},
|
||||
body::{HttpBody, Buf, Body},
|
||||
body::{Buf, Incoming},
|
||||
};
|
||||
use http_body_util::BodyExt;
|
||||
|
||||
use crate::{Client, Error};
|
||||
|
||||
// Borrows the client so its async task lives as long as this response exists.
|
||||
#[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> {
|
||||
pub fn status(&self) -> StatusCode {
|
||||
self.0.status()
|
||||
|
|
Loading…
Reference in a new issue