diff --git a/Cargo.lock b/Cargo.lock index c58ae27c8863eb73f5242c716fce07f88ab6cbc3..56f17318aa36207b36dce4b2fe7e3bbd147e52c2 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 d49fdbfcb1702568302b05147917da88e7358e26..4f853a62048ac701feb60d6f9e742bafcf3ec065 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 e36d71b3dc29e1238986226d001f30312468dc1e..ed99e2e64e9c388f22abe062cecc45fcf4660a81 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 658c32ecfa119bc427d547b1d4d695b47f63da5a..e6870bf2f8a2340be6e6524a9e8dd405ba27d8c9 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 633a785c3701f595ee3342f6552190f0c648a198..423bb66f7cd728a79dc444eb6d78680ce7ee66c3 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 6f19b16860f1c18c4968177612345a6a2236cd91..ebf296c27d65d8315f594d4558bd5d7d7ec8727e 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 0000000000000000000000000000000000000000..a55268ac314ebe4a45d2aaa53c6281f8ebac6aa2 --- /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 0000000000000000000000000000000000000000..1cd601d0a3affae83854be02a0afdec3b7a9ec4d --- /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 0000000000000000000000000000000000000000..8ddde5c15a01487bd5baf22fe66743cfd92f51a4 --- /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 e02e7b7e52f54d8bd750c81377b11d2abe0b08e6..4881210546dd652503a7e6a212f4a2825e9e26f7 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 010d0f653912196405af3af0533a4651d71b7117..c523aba5ae30a27a5e6b10c99157c968eae72449 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;