From 8f560daec2bb848098e75c7949b71204a6de0f85 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Mon, 17 Mar 2025 03:36:37 +0100 Subject: [PATCH] chore: Extract http-client-tls crate (#26895) http-client pulled in rustls which in turn meant that gpui depended on rustls/aws-lc-sys. This commit extracts http-client-tls crate to separate the http-client and tls dependencies. Closes #ISSUE Release Notes: - N/A --- Cargo.lock | 12 +++++++++-- Cargo.toml | 2 ++ crates/client/Cargo.toml | 1 + crates/client/src/client.rs | 2 +- crates/http_client/Cargo.toml | 2 -- crates/http_client/src/http_client.rs | 21 +------------------ crates/http_client_tls/Cargo.toml | 20 ++++++++++++++++++ crates/http_client_tls/LICENSE-APACHE | 1 + crates/http_client_tls/src/http_client_tls.rs | 21 +++++++++++++++++++ crates/reqwest_client/Cargo.toml | 1 + crates/reqwest_client/src/reqwest_client.rs | 2 +- 11 files changed, 59 insertions(+), 26 deletions(-) create mode 100644 crates/http_client_tls/Cargo.toml create mode 120000 crates/http_client_tls/LICENSE-APACHE create mode 100644 crates/http_client_tls/src/http_client_tls.rs diff --git a/Cargo.lock b/Cargo.lock index c58ae27c88..56f17318aa 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.toml index d49fdbfcb1..4f853a6204 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.toml index e36d71b3dc..ed99e2e64e 100644 --- a/crates/client/Cargo.toml +++ b/crates/client/Cargo.toml @@ -27,6 +27,7 @@ feature_flags.workspace = true futures.workspace = true gpui.workspace = true http_client.workspace = true +http_client_tls.workspace = true log.workspace = true paths.workspace = true parking_lot.workspace = true diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 658c32ecfa..e6870bf2f8 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.toml index 633a785c37..423bb66f7c 100644 --- a/crates/http_client/Cargo.toml +++ b/crates/http_client/Cargo.toml @@ -25,5 +25,3 @@ log.workspace = true serde.workspace = true serde_json.workspace = true url.workspace = true -rustls.workspace = true -rustls-platform-verifier.workspace = true diff --git a/crates/http_client/src/http_client.rs b/crates/http_client/src/http_client.rs index 6f19b16860..ebf296c27d 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 = 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.toml new file mode 100644 index 0000000000..a55268ac31 --- /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 = true diff --git a/crates/http_client_tls/LICENSE-APACHE b/crates/http_client_tls/LICENSE-APACHE new file mode 120000 index 0000000000..1cd601d0a3 --- /dev/null +++ b/crates/http_client_tls/LICENSE-APACHE @@ -0,0 +1 @@ +../../LICENSE-APACHE \ No newline at end of file diff --git a/crates/http_client_tls/src/http_client_tls.rs b/crates/http_client_tls/src/http_client_tls.rs new file mode 100644 index 0000000000..8ddde5c15a --- /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 = 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.toml index e02e7b7e52..4881210546 100644 --- a/crates/reqwest_client/Cargo.toml +++ b/crates/reqwest_client/Cargo.toml @@ -24,6 +24,7 @@ anyhow.workspace = true bytes.workspace = true futures.workspace = true http_client.workspace = true +http_client_tls.workspace = true serde.workspace = true smol.workspace = true log.workspace = true diff --git a/crates/reqwest_client/src/reqwest_client.rs b/crates/reqwest_client/src/reqwest_client.rs index 010d0f6539..c523aba5ae 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;