Skip to content

Commit 0ff931f

Browse files
committed
fix!: prefer curl over reqwest connections if both are enabled
1 parent cbf7445 commit 0ff931f

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

gix-transport/src/client/blocking_io/connect.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {
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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,6 @@ impl Default for Options {
215215
}
216216
}
217217

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-
225218
/// A transport for supporting arbitrary http clients by abstracting interactions with them into the [Http] trait.
226219
pub struct Transport<H: Http> {
227220
url: String,
@@ -270,13 +263,13 @@ impl<H: Http> Transport<H> {
270263
}
271264

272265
#[cfg(any(feature = "http-client-curl", feature = "http-client-reqwest"))]
273-
impl Transport<Impl> {
266+
impl<H: Http + Default> Transport<H> {
274267
/// Create a new instance to communicate to `url` using the given `desired_version` of the `git` protocol.
275268
/// If `trace` is `true`, all packetlines received or sent will be passed to the facilities of the `gix-trace` crate.
276269
///
277270
/// Note that the actual implementation depends on feature toggles.
278271
pub fn new(url: gix_url::Url, desired_version: Protocol, trace: bool) -> Self {
279-
Self::new_http(Impl::default(), url, desired_version, trace)
272+
Self::new_http(H::default(), url, desired_version, trace)
280273
}
281274
}
282275

@@ -555,7 +548,7 @@ pub fn connect_http<H: Http>(http: H, url: gix_url::Url, desired_version: Protoc
555548
/// Connect to the given `url` via HTTP/S using the `desired_version` of the `git` protocol.
556549
/// If `trace` is `true`, all packetlines received or sent will be passed to the facilities of the `gix-trace` crate.
557550
#[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> {
551+
pub fn connect<H: Http + Default>(url: gix_url::Url, desired_version: Protocol, trace: bool) -> Transport<H> {
559552
Transport::new(url, desired_version, trace)
560553
}
561554

0 commit comments

Comments
 (0)