Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions gix-transport/src/client/blocking_io/connect.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
pub use crate::client::non_io_types::connect::{Error, Options};

pub(crate) mod function {
#[cfg(feature = "http-client-curl")]
use crate::client::blocking_io::http::curl::Curl;
#[cfg(feature = "http-client-reqwest")]
use crate::client::blocking_io::http::reqwest::Remote;
use crate::client::{blocking_io::Transport, non_io_types::connect::Error};

/// A general purpose connector connecting to a repository identified by the given `url`.
Expand Down Expand Up @@ -57,11 +61,15 @@ pub(crate) mod function {
}
#[cfg(not(any(feature = "http-client-curl", feature = "http-client-reqwest")))]
gix_url::Scheme::Https | gix_url::Scheme::Http => return Err(Error::CompiledWithoutHttp(url.scheme)),
#[cfg(any(feature = "http-client-curl", feature = "http-client-reqwest"))]
gix_url::Scheme::Https | gix_url::Scheme::Http => Box::new(crate::client::blocking_io::http::connect(
url,
options.version,
options.trace,
#[cfg(feature = "http-client-curl")]
gix_url::Scheme::Https | gix_url::Scheme::Http => Box::new(
crate::client::blocking_io::http::connect::<Curl>(url, options.version, options.trace),
),
#[cfg(all(feature = "http-client-reqwest", not(feature = "http-client-curl")))]
gix_url::Scheme::Https | gix_url::Scheme::Http => Box::new(crate::client::blocking_io::http::connect::<
Remote,
>(
url, options.version, options.trace
)),
})
}
Expand Down
16 changes: 3 additions & 13 deletions gix-transport/src/client/blocking_io/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ use crate::{
Protocol, Service,
};

#[cfg(all(feature = "http-client-reqwest", feature = "http-client-curl"))]
compile_error!("Cannot set both 'http-client-reqwest' and 'http-client-curl' features as they are mutually exclusive");

#[cfg(feature = "http-client-curl")]
///
pub mod curl;
Expand Down Expand Up @@ -215,13 +212,6 @@ impl Default for Options {
}
}

/// The actual http client implementation, using curl
#[cfg(feature = "http-client-curl")]
pub type Impl = curl::Curl;
/// The actual http client implementation, using reqwest
#[cfg(feature = "http-client-reqwest")]
pub type Impl = reqwest::Remote;

Comment on lines -219 to -224
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I wanted to bring Impl back as it's a nice way to get the implementation of what's actually implemented, but then I realised that this is quite an implementation detail and it's probably unused outside of this crate anyway.

/// A transport for supporting arbitrary http clients by abstracting interactions with them into the [Http] trait.
pub struct Transport<H: Http> {
url: String,
Expand Down Expand Up @@ -270,13 +260,13 @@ impl<H: Http> Transport<H> {
}

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

Expand Down Expand Up @@ -555,7 +545,7 @@ pub fn connect_http<H: Http>(http: H, url: gix_url::Url, desired_version: Protoc
/// Connect to the given `url` via HTTP/S using the `desired_version` of the `git` protocol.
/// If `trace` is `true`, all packetlines received or sent will be passed to the facilities of the `gix-trace` crate.
#[cfg(any(feature = "http-client-curl", feature = "http-client-reqwest"))]
pub fn connect(url: gix_url::Url, desired_version: Protocol, trace: bool) -> Transport<Impl> {
pub fn connect<H: Http + Default>(url: gix_url::Url, desired_version: Protocol, trace: bool) -> Transport<H> {
Transport::new(url, desired_version, trace)
}

Expand Down
Loading