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 @@
1pub use crate::client::non_io_types::connect::{Error, Options};1pub use crate::client::non_io_types::connect::{Error, Options};
2 2
3pub(crate) mod function {3pub(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;
4 use crate::client::{blocking_io::Transport, non_io_types::connect::Error};8 use crate::client::{blocking_io::Transport, non_io_types::connect::Error};
5 9
6 /// A general purpose connector connecting to a repository identified by the given `url`.10 /// A general purpose connector connecting to a repository identified by the given `url`.
@@ -57,11 +61,15 @@ pub(crate) mod function { · 50 unmodified lines
57 }61 }
58 #[cfg(not(any(feature = "http-client-curl", feature = "http-client-reqwest")))]62 #[cfg(not(any(feature = "http-client-curl", feature = "http-client-reqwest")))]
59 gix_url::Scheme::Https | gix_url::Scheme::Http => return Err(Error::CompiledWithoutHttp(url.scheme)),63 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"))]64 #[cfg(feature = "http-client-curl")]
61 gix_url::Scheme::Https | gix_url::Scheme::Http => Box::new(crate::client::blocking_io::http::connect(65 gix_url::Scheme::Https | gix_url::Scheme::Http => Box::new(
62 url,66 crate::client::blocking_io::http::connect::<Curl>(url, options.version, options.trace),
63 options.version,67 ),
64 options.trace,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
65 )),73 )),
66 })74 })
67 }75 }
gix-transport/src/client/blocking_io/http/mod.rs+3−13
@@ -25,9 +25,6 @@ use crate::{ · 24 unmodified lines
25 Protocol, Service,25 Protocol, Service,
26};26};
27 27
28#[cfg(all(feature = "http-client-reqwest", feature = "http-client-curl"))]
29compile_error!("Cannot set both 'http-client-reqwest' and 'http-client-curl' features as they are mutually exclusive");
30
31#[cfg(feature = "http-client-curl")]28#[cfg(feature = "http-client-curl")]
32///29///
33pub mod curl;30pub mod curl;
@@ -215,13 +212,6 @@ impl Default for Options { · 181 unmodified lines
215 }212 }
216}213}
217 214
218/// The actual http client implementation, using curl
219#[cfg(feature = "http-client-curl")]
220pub type Impl = curl::Curl;
221/// The actual http client implementation, using reqwest
222#[cfg(feature = "http-client-reqwest")]
223pub type Impl = reqwest::Remote;
224
225/// A transport for supporting arbitrary http clients by abstracting interactions with them into the [Http] trait.215/// A transport for supporting arbitrary http clients by abstracting interactions with them into the [Http] trait.
226pub struct Transport<H: Http> {216pub struct Transport<H: Http> {
227 url: String,217 url: String,
@@ -270,13 +260,13 @@ impl<H: Http> Transport<H> { · 42 unmodified lines
270}260}
271 261
272#[cfg(any(feature = "http-client-curl", feature = "http-client-reqwest"))]262#[cfg(any(feature = "http-client-curl", feature = "http-client-reqwest"))]
273impl Transport<Impl> {263impl<H: Http + Default> Transport<H> {
274 /// Create a new instance to communicate to `url` using the given `desired_version` of the `git` protocol.264 /// Create a new instance to communicate to `url` using the given `desired_version` of the `git` protocol.
275 /// If `trace` is `true`, all packetlines received or sent will be passed to the facilities of the `gix-trace` crate.265 /// If `trace` is `true`, all packetlines received or sent will be passed to the facilities of the `gix-trace` crate.
276 ///266 ///
277 /// Note that the actual implementation depends on feature toggles.267 /// Note that the actual implementation depends on feature toggles.
278 pub fn new(url: gix_url::Url, desired_version: Protocol, trace: bool) -> Self {268 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)
280 }270 }
281}271}
282 272
@@ -555,7 +545,7 @@ pub fn connect_http<H: Http>(http: H, url: gix_url::Url, desired_version: Protoc · 272 unmodified lines
555/// Connect to the given `url` via HTTP/S using the `desired_version` of the `git` protocol.545/// Connect to the given `url` via HTTP/S using the `desired_version` of the `git` protocol.
556/// If `trace` is `true`, all packetlines received or sent will be passed to the facilities of the `gix-trace` crate.546/// If `trace` is `true`, all packetlines received or sent will be passed to the facilities of the `gix-trace` crate.
557#[cfg(any(feature = "http-client-curl", feature = "http-client-reqwest"))]547#[cfg(any(feature = "http-client-curl", feature = "http-client-reqwest"))]
558pub fn connect(url: gix_url::Url, desired_version: Protocol, trace: bool) -> Transport<Impl> {548pub fn connect<H: Http + Default>(url: gix_url::Url, desired_version: Protocol, trace: bool) -> Transport<H> {
559 Transport::new(url, desired_version, trace)549 Transport::new(url, desired_version, trace)
560}550}
561 551