Skip to content

Commit

Permalink
Merge branch 'paulyoung/git-transport-http-client'
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Sep 27, 2022
2 parents e5df989 + 0fd57c6 commit c845c16
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ check: ## Build all code in suitable configurations
&& cargo check --features blocking-client \
&& cargo check --features async-client \
&& cargo check --features async-client,async-std \
&& cargo check --features http-client \
&& cargo check --features http-client-curl
cd git-transport && if cargo check --all-features 2>/dev/null; then false; else true; fi
cd git-protocol && cargo check \
Expand Down
10 changes: 7 additions & 3 deletions git-transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ default = []

## If set, blocking implementations of the typical git transports become available in `crate::client`
blocking-client = ["git-packetline/blocking-io"]
## Implies `blocking-client`, and adds support for the http and https transports using the Rust bindings for `libcurl`.
http-client-curl = ["curl", "base64", "git-features/io-pipe", "blocking-client"]
## Implies `blocking-client`, and adds support for the http and https transports.
http-client = ["base64", "git-features/io-pipe", "blocking-client"]
## Implies `http-client`, and adds support for the http and https transports using the Rust bindings for `libcurl`.
http-client-curl = ["curl", "http-client"]
## If set, an async implementations of the git transports becomes available in `crate::client`.
## Suitable for implementing your own transports while using git's way of communication, typically in conjunction with a custom server.
## **Note** that the _blocking_ client has a wide range of available transports, with the _async_ version of it supporting only the TCP based `git` transport leaving you
Expand Down Expand Up @@ -62,11 +64,13 @@ futures-io = { version = "0.3.16", optional = true }
futures-lite = { version = "1.12.0", optional = true }
pin-project-lite = { version = "0.2.6", optional = true }

# for http-client
base64 = { version = "0.13.0", optional = true }

# for http-client-curl
# zlib-ng-compat doesn't force zlib-ng
curl = { version = "0.4", optional = true, features = ["static-curl", "static-ssl", "zlib-ng-compat"] }
thiserror = "1.0.26"
base64 = { version = "0.13.0", optional = true }

## If used in conjunction with `async-client`, the `connect()` method will be come available along with supporting the git protocol over TCP,
## where the TCP stream is created using this crate.
Expand Down
25 changes: 21 additions & 4 deletions git-transport/src/client/blocking_io/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,33 @@ pub struct Transport<H: Http> {
identity: Option<git_sec::identity::Account>,
}

impl Transport<Impl> {
/// Create a new instance to communicate to `url` using the given `desired_version` of the `git` protocol.
pub fn new(url: &str, desired_version: Protocol) -> Self {
impl<H: Http> Transport<H> {
/// Create a new instance with `http` as implementation to communicate to `url` using the given `desired_version` of the `git` protocol.
pub fn new_http(http: H, url: &str, desired_version: Protocol) -> Self {
Transport {
url: url.to_owned(),
user_agent_header: concat!("User-Agent: git/oxide-", env!("CARGO_PKG_VERSION")),
desired_version,
actual_version: desired_version,
supported_versions: [desired_version],
service: None,
http: Impl::default(),
http,
line_provider: None,
identity: None,
}
}
}

#[cfg(feature = "http-client-curl")]
impl Transport<Impl> {
/// Create a new instance to communicate to `url` using the given `desired_version` of the `git` protocol.
///
/// Note that the actual implementation depends on feature toggles.
pub fn new(url: &str, desired_version: Protocol) -> Self {
Self::new_http(Impl::default(), url, desired_version)
}
}

impl<H: Http> Transport<H> {
fn check_content_type(service: Service, kind: &str, headers: <H as Http>::Headers) -> Result<(), client::Error> {
let wanted_content_type = format!("Content-Type: application/x-{}-{}", service.as_str(), kind);
Expand Down Expand Up @@ -285,7 +295,14 @@ impl<H: Http, B: ExtendedBufRead + Unpin> ExtendedBufRead for HeadersThenBody<H,
}
}

/// Connect to the given `url` via HTTP/S using the `desired_version` of the `git` protocol, with `http` as implementation.
#[cfg(all(feature = "http-client", not(feature = "http-client-curl")))]
pub fn connect_http<H: Http>(http: H, url: &str, desired_version: Protocol) -> Result<Transport<H>, Infallible> {
Ok(Transport::new_http(http, url, desired_version))
}

/// Connect to the given `url` via HTTP/S using the `desired_version` of the `git` protocol.
#[cfg(feature = "http-client-curl")]
pub fn connect(url: &str, desired_version: Protocol) -> Result<Transport<Impl>, Infallible> {
Ok(Transport::new(url, desired_version))
}
2 changes: 1 addition & 1 deletion git-transport/src/client/blocking_io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub mod connect;
///
pub mod file;
///
#[cfg(feature = "http-client-curl")]
#[cfg(feature = "http-client")]
pub mod http;

mod bufread_ext;
Expand Down
2 changes: 1 addition & 1 deletion git-transport/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub use traits::TransportWithoutIO;

#[cfg(feature = "blocking-client")]
mod blocking_io;
#[cfg(all(feature = "blocking-client", feature = "http-client-curl"))]
#[cfg(feature = "http-client")]
pub use blocking_io::http;
#[cfg(feature = "blocking-client")]
pub use blocking_io::{
Expand Down
6 changes: 3 additions & 3 deletions git-transport/src/client/non_io_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ mod error {
use bstr::BString;

use crate::client::capabilities;
#[cfg(feature = "http-client-curl")]
#[cfg(feature = "http-client")]
use crate::client::http;

#[cfg(feature = "http-client-curl")]
#[cfg(feature = "http-client")]
type HttpError = http::Error;
#[cfg(not(feature = "http-client-curl"))]
#[cfg(not(feature = "http-client"))]
type HttpError = std::convert::Infallible;

/// The error used in most methods of the [`client`][crate::client] module
Expand Down

0 comments on commit c845c16

Please sign in to comment.