Revert http client changes (#18892)

These proved to be too unstable. Will restore these changes once the issues have been fixed.

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2024-10-09 01:07:18 -07:00 committed by GitHub
parent e351148152
commit 5d5c4b6677
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 386 additions and 1125 deletions

View file

@ -16,13 +16,11 @@ path = "src/http_client.rs"
doctest = true
[dependencies]
http = "0.2"
anyhow.workspace = true
derive_more.workspace = true
futures.workspace = true
http = "1.1"
log.workspace = true
rustls-native-certs.workspace = true
rustls.workspace = true
serde.workspace = true
serde_json.workspace = true
smol.workspace = true

View file

@ -11,22 +11,13 @@ use http::request::Builder;
#[cfg(feature = "test-support")]
use std::fmt;
use std::{
any::type_name,
sync::{Arc, LazyLock, Mutex},
sync::{Arc, Mutex},
time::Duration,
};
pub use url::Url;
#[derive(Clone)]
pub struct ReadTimeout(pub Duration);
impl Default for ReadTimeout {
fn default() -> Self {
Self(Duration::from_secs(5))
}
}
#[derive(Default, Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Default, Debug, Clone)]
pub enum RedirectPolicy {
#[default]
NoFollow,
@ -35,23 +26,6 @@ pub enum RedirectPolicy {
}
pub struct FollowRedirects(pub bool);
pub static TLS_CONFIG: LazyLock<Arc<rustls::ClientConfig>> = LazyLock::new(|| {
let mut root_store = rustls::RootCertStore::empty();
let root_certs = rustls_native_certs::load_native_certs();
for error in root_certs.errors {
log::warn!("error loading native certs: {:?}", error);
}
root_store.add_parsable_certificates(&root_certs.certs);
Arc::new(
rustls::ClientConfig::builder()
.with_safe_defaults()
.with_root_certificates(root_store)
.with_no_client_auth(),
)
});
pub trait HttpRequestExt {
/// Set a read timeout on the request.
/// For isahc, this is the low_speed_timeout.
@ -73,8 +47,6 @@ impl HttpRequestExt for http::request::Builder {
}
pub trait HttpClient: 'static + Send + Sync {
fn type_name(&self) -> &'static str;
fn send(
&self,
req: http::Request<AsyncBody>,
@ -157,10 +129,6 @@ impl HttpClient for HttpClientWithProxy {
fn proxy(&self) -> Option<&Uri> {
self.proxy.as_ref()
}
fn type_name(&self) -> &'static str {
self.client.type_name()
}
}
impl HttpClient for Arc<HttpClientWithProxy> {
@ -174,10 +142,6 @@ impl HttpClient for Arc<HttpClientWithProxy> {
fn proxy(&self) -> Option<&Uri> {
self.proxy.as_ref()
}
fn type_name(&self) -> &'static str {
self.client.type_name()
}
}
/// An [`HttpClient`] that has a base URL.
@ -289,10 +253,6 @@ impl HttpClient for Arc<HttpClientWithUrl> {
fn proxy(&self) -> Option<&Uri> {
self.client.proxy.as_ref()
}
fn type_name(&self) -> &'static str {
self.client.type_name()
}
}
impl HttpClient for HttpClientWithUrl {
@ -306,10 +266,6 @@ impl HttpClient for HttpClientWithUrl {
fn proxy(&self) -> Option<&Uri> {
self.client.proxy.as_ref()
}
fn type_name(&self) -> &'static str {
self.client.type_name()
}
}
pub fn read_proxy_from_env() -> Option<Uri> {
@ -350,10 +306,6 @@ impl HttpClient for BlockedHttpClient {
fn proxy(&self) -> Option<&Uri> {
None
}
fn type_name(&self) -> &'static str {
type_name::<Self>()
}
}
#[cfg(feature = "test-support")]
@ -426,8 +378,4 @@ impl HttpClient for FakeHttpClient {
fn proxy(&self) -> Option<&Uri> {
None
}
fn type_name(&self) -> &'static str {
type_name::<Self>()
}
}