Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
chore: Extract http-client-tls crate (#26895)
Piotr Osiewicz8f560daec2bb
diff --git a/Cargo.lock b/Cargo.lockindex c58ae27c886..56f17318aa3 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -2739,6 +2739,7 @@ dependencies = ["futures 0.3.31","gpui","http_client",+ "http_client_tls","log","parking_lot","paths",@@ -6201,13 +6202,19 @@ dependencies = ["futures 0.3.31","http 1.2.0","log",- "rustls 0.23.23",- "rustls-platform-verifier","serde","serde_json","url",]+[[package]]+name = "http_client_tls"+version = "0.1.0"+dependencies = [+ "rustls 0.23.23",+ "rustls-platform-verifier",+]+[[package]]name = "httparse"version = "1.9.5"@@ -11460,6 +11467,7 @@ dependencies = ["futures 0.3.31","gpui","http_client",+ "http_client_tls","log","regex","reqwest 0.12.8",diff --git a/Cargo.toml b/Cargo.tomlindex d49fdbfcb17..4f853a62048 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -65,6 +65,7 @@ members = ["crates/gpui_tokio","crates/html_to_markdown","crates/http_client",+ "crates/http_client_tls","crates/image_viewer","crates/indexed_docs","crates/inline_completion",@@ -262,6 +263,7 @@ gpui_macros = { path = "crates/gpui_macros" }gpui_tokio = { path = "crates/gpui_tokio" }html_to_markdown = { path = "crates/html_to_markdown" }http_client = { path = "crates/http_client" }+http_client_tls = { path = "crates/http_client_tls" }image_viewer = { path = "crates/image_viewer" }indexed_docs = { path = "crates/indexed_docs" }inline_completion = { path = "crates/inline_completion" }diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.tomlindex e36d71b3dc2..ed99e2e64e9 100644--- a/crates/client/Cargo.toml+++ b/crates/client/Cargo.toml@@ -27,6 +27,7 @@ feature_flags.workspace = truefutures.workspace = truegpui.workspace = truehttp_client.workspace = true+http_client_tls.workspace = truelog.workspace = truepaths.workspace = trueparking_lot.workspace = truediff --git a/crates/client/src/client.rs b/crates/client/src/client.rsindex 658c32ecfa1..e6870bf2f8a 100644--- a/crates/client/src/client.rs+++ b/crates/client/src/client.rs@@ -1154,7 +1154,7 @@ impl Client {async_tungstenite::async_tls::client_async_tls_with_connector(request,stream,- Some(http_client::tls_config().into()),+ Some(http_client_tls::tls_config().into()),).await?;Ok(Connection::new(diff --git a/crates/http_client/Cargo.toml b/crates/http_client/Cargo.tomlindex 633a785c370..423bb66f7cd 100644--- a/crates/http_client/Cargo.toml+++ b/crates/http_client/Cargo.toml@@ -25,5 +25,3 @@ log.workspace = trueserde.workspace = trueserde_json.workspace = trueurl.workspace = true-rustls.workspace = true-rustls-platform-verifier.workspace = truediff --git a/crates/http_client/src/http_client.rs b/crates/http_client/src/http_client.rsindex 6f19b16860f..ebf296c27d6 100644--- a/crates/http_client/src/http_client.rs+++ b/crates/http_client/src/http_client.rs@@ -8,33 +8,14 @@ pub use http::{self, Method, Request, Response, StatusCode, Uri};use futures::future::BoxFuture;use http::request::Builder;-use rustls::ClientConfig;-use rustls_platform_verifier::ConfigVerifierExt;#[cfg(feature = "test-support")]use std::fmt;use std::{any::type_name,- sync::{Arc, Mutex, OnceLock},+ sync::{Arc, Mutex},};pub use url::Url;-static TLS_CONFIG: OnceLock<rustls::ClientConfig> = OnceLock::new();--pub fn tls_config() -> ClientConfig {- TLS_CONFIG- .get_or_init(|| {- // rustls uses the `aws_lc_rs` provider by default- // This only errors if the default provider has already- // been installed. We can ignore this `Result`.- rustls::crypto::aws_lc_rs::default_provider()- .install_default()- .ok();-- ClientConfig::with_platform_verifier()- })- .clone()-}-#[derive(Default, Debug, Clone, PartialEq, Eq, Hash)]pub enum RedirectPolicy {#[default]diff --git a/crates/http_client_tls/Cargo.toml b/crates/http_client_tls/Cargo.tomlnew file mode 100644index 00000000000..a55268ac314--- /dev/null+++ b/crates/http_client_tls/Cargo.toml@@ -0,0 +1,20 @@+[package]+name = "http_client_tls"+version = "0.1.0"+edition.workspace = true+publish.workspace = true+license = "Apache-2.0"++[lints]+workspace = true++[features]+test-support = []++[lib]+path = "src/http_client_tls.rs"+doctest = true++[dependencies]+rustls.workspace = true+rustls-platform-verifier.workspace = truediff --git a/crates/http_client_tls/LICENSE-APACHE b/crates/http_client_tls/LICENSE-APACHEnew file mode 120000index 00000000000..1cd601d0a3a--- /dev/null+++ b/crates/http_client_tls/LICENSE-APACHE@@ -0,0 +1 @@+../../LICENSE-APACHE\ No newline at end of filediff --git a/crates/http_client_tls/src/http_client_tls.rs b/crates/http_client_tls/src/http_client_tls.rsnew file mode 100644index 00000000000..8ddde5c15a0--- /dev/null+++ b/crates/http_client_tls/src/http_client_tls.rs@@ -0,0 +1,21 @@+use std::sync::OnceLock;++use rustls::ClientConfig;+use rustls_platform_verifier::ConfigVerifierExt;++static TLS_CONFIG: OnceLock<rustls::ClientConfig> = OnceLock::new();++pub fn tls_config() -> ClientConfig {+ TLS_CONFIG+ .get_or_init(|| {+ // rustls uses the `aws_lc_rs` provider by default+ // This only errors if the default provider has already+ // been installed. We can ignore this `Result`.+ rustls::crypto::aws_lc_rs::default_provider()+ .install_default()+ .ok();++ ClientConfig::with_platform_verifier()+ })+ .clone()+}diff --git a/crates/reqwest_client/Cargo.toml b/crates/reqwest_client/Cargo.tomlindex e02e7b7e52f..4881210546d 100644--- a/crates/reqwest_client/Cargo.toml+++ b/crates/reqwest_client/Cargo.toml@@ -24,6 +24,7 @@ anyhow.workspace = truebytes.workspace = truefutures.workspace = truehttp_client.workspace = true+http_client_tls.workspace = trueserde.workspace = truesmol.workspace = truelog.workspace = truediff --git a/crates/reqwest_client/src/reqwest_client.rs b/crates/reqwest_client/src/reqwest_client.rsindex 010d0f65391..c523aba5ae3 100644--- a/crates/reqwest_client/src/reqwest_client.rs+++ b/crates/reqwest_client/src/reqwest_client.rs@@ -56,7 +56,7 @@ impl ReqwestClient {}let client = client- .use_preconfigured_tls(http_client::tls_config())+ .use_preconfigured_tls(http_client_tls::tls_config()).build()?;let mut client: ReqwestClient = client.into();client.proxy = proxy;