History

fix!: prefer curl over reqwest connections if both are enabled

Dirkjan Ochtman committed 1 year ago

Commit 35d64b81 parent cbf74452 files · +16 −18Browse files

Unified · Split

2 files
  1. gix-transport/src/client/blocking_io/connect.rs +13 −5
  2. gix-transport/src/client/blocking_io/http/mod.rs +3 −13
gix-transport/src/client/blocking_io/connect.rs+13−5
@@ -1,6 +1,10 @@
11 pub use crate::client::non_io_types::connect::{Error, Options};
22
33 pub(crate) mod function {
4+ #[cfg(feature = "http-client-curl")]
5+ use crate::client::blocking_io::http::curl::Curl;
6+ #[cfg(feature = "http-client-reqwest")]
7+ use crate::client::blocking_io::http::reqwest::Remote;
48 use crate::client::{blocking_io::Transport, non_io_types::connect::Error};
59
610 /// A general purpose connector connecting to a repository identified by the given `url`.
@@ -57,11 +61,15 @@ pub(crate) mod function { · 50 unmodified lines
5761 }
5862 #[cfg(not(any(feature = "http-client-curl", feature = "http-client-reqwest")))]
5963 gix_url::Scheme::Https | gix_url::Scheme::Http => return Err(Error::CompiledWithoutHttp(url.scheme)),
60− #[cfg(any(feature = "http-client-curl", feature = "http-client-reqwest"))]
61− gix_url::Scheme::Https | gix_url::Scheme::Http => Box::new(crate::client::blocking_io::http::connect(
62− url,
63− options.version,
64− options.trace,
64+ #[cfg(feature = "http-client-curl")]
65+ gix_url::Scheme::Https | gix_url::Scheme::Http => Box::new(
66+ crate::client::blocking_io::http::connect::<Curl>(url, options.version, options.trace),
67+ ),
68+ #[cfg(all(feature = "http-client-reqwest", not(feature = "http-client-curl")))]
69+ gix_url::Scheme::Https | gix_url::Scheme::Http => Box::new(crate::client::blocking_io::http::connect::<
70+ Remote,
71+ >(
72+ url, options.version, options.trace
6573 )),
6674 })
6775 }
gix-transport/src/client/blocking_io/http/mod.rs+3−13
@@ -25,9 +25,6 @@ use crate::{ · 24 unmodified lines
2525 Protocol, Service,
2626 };
2727
28−#[cfg(all(feature = "http-client-reqwest", feature = "http-client-curl"))]
29−compile_error!("Cannot set both 'http-client-reqwest' and 'http-client-curl' features as they are mutually exclusive");
30−
3128 #[cfg(feature = "http-client-curl")]
3229 ///
3330 pub mod curl;
@@ -215,13 +212,6 @@ impl Default for Options { · 181 unmodified lines
215212 }
216213 }
217214
218−/// The actual http client implementation, using curl
219−#[cfg(feature = "http-client-curl")]
220−pub type Impl = curl::Curl;
221−/// The actual http client implementation, using reqwest
222−#[cfg(feature = "http-client-reqwest")]
223−pub type Impl = reqwest::Remote;
224−
225215 /// A transport for supporting arbitrary http clients by abstracting interactions with them into the [Http] trait.
226216 pub struct Transport<H: Http> {
227217 url: String,
@@ -270,13 +260,13 @@ impl<H: Http> Transport<H> { · 42 unmodified lines
270260 }
271261
272262 #[cfg(any(feature = "http-client-curl", feature = "http-client-reqwest"))]
273−impl Transport<Impl> {
263+impl<H: Http + Default> Transport<H> {
274264 /// Create a new instance to communicate to `url` using the given `desired_version` of the `git` protocol.
275265 /// If `trace` is `true`, all packetlines received or sent will be passed to the facilities of the `gix-trace` crate.
276266 ///
277267 /// Note that the actual implementation depends on feature toggles.
278268 pub fn new(url: gix_url::Url, desired_version: Protocol, trace: bool) -> Self {
279− Self::new_http(Impl::default(), url, desired_version, trace)
269+ Self::new_http(H::default(), url, desired_version, trace)
280270 }
281271 }
282272
@@ -555,7 +545,7 @@ pub fn connect_http<H: Http>(http: H, url: gix_url::Url, desired_version: Protoc · 272 unmodified lines
555545 /// Connect to the given `url` via HTTP/S using the `desired_version` of the `git` protocol.
556546 /// If `trace` is `true`, all packetlines received or sent will be passed to the facilities of the `gix-trace` crate.
557547 #[cfg(any(feature = "http-client-curl", feature = "http-client-reqwest"))]
558−pub fn connect(url: gix_url::Url, desired_version: Protocol, trace: bool) -> Transport<Impl> {
548+pub fn connect<H: Http + Default>(url: gix_url::Url, desired_version: Protocol, trace: bool) -> Transport<H> {
559549 Transport::new(url, desired_version, trace)
560550 }
561551