Skip to content

Commit

Permalink
[clone] sketch for http infrastructure to get going with curl
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 21, 2020
1 parent 8b082d0 commit 8351299
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ doctest = false
[features]
default = ["max"]

max = ["fast", "pretty-cli", "prodash/render-tui-crossterm", "prodash-render-line-crossterm", "http-curl"]
max-termion = ["fast", "pretty-cli", "prodash/render-tui-termion", "prodash-render-line-termion", "http-curl"]
max = ["fast", "pretty-cli", "prodash/render-tui-crossterm", "prodash-render-line-crossterm", "http-client-curl"]
max-termion = ["fast", "pretty-cli", "prodash/render-tui-termion", "prodash-render-line-termion", "http-client-curl"]

lean = ["fast", "lean-cli", "prodash-render-line-crossterm", "git-features/interrupt-handler", "prodash/progress-tree"]
lean-termion = ["fast", "lean-cli", "prodash-render-line-termion", "git-features/interrupt-handler", "prodash/progress-tree"]

light = ["fast", "lean-cli", "git-features/interrupt-handler"]
small = ["lean-cli"]
http-curl = ["git-transport/http-curl"]
http-client-curl = ["git-transport/http-client-curl"]

fast = ["git-features/parallel", "git-features/fast-sha1"]
pretty-cli = ["clap",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ All feature toggles are additive.

### git-transport

* **http-curl**
* **http-client-curl**
* Adds support for the http and https transports using the Rust bindings for `libcurl`

### Serialization Support
Expand Down
4 changes: 2 additions & 2 deletions git-transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ doctest = false

[features]
serde1 = ["serde"]
http-curl = ["curl"]
http-client-curl = ["curl"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -26,5 +26,5 @@ serde = { version = "1.0.114", optional = true, default-features = false, featur
quick-error = "2.0.0"
bstr = { version = "0.2.13", default-features = false, features = ["std"] }

# for http-curl
# for http-client-curl
curl = { version = "0.4.31", optional = true, features = ["static-ssl", "static-curl"] }
6 changes: 3 additions & 3 deletions git-transport/src/client/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ quick_error! {
UnsupportedUrlTokens(url: bstr::BString, scheme: git_url::Protocol) {
display("The url '{}' contains information that would not be used by the '{}' protocol", url, scheme)
}
#[cfg(not(feature = "http-curl"))]
#[cfg(not(feature = "http-client-curl"))]
CompiledWithoutHttp(scheme: git_url::Protocol) {
display("'{}' is not compiled in. Compile with the 'http' cargo feature", scheme)
}
Expand Down Expand Up @@ -67,9 +67,9 @@ pub fn connect(url: &[u8], version: crate::Protocol) -> Result<Box<dyn Transport
.map_err(|e| Box::new(e) as Box<dyn std::error::Error + Send + Sync>)?,
)
}
#[cfg(not(feature = "http-curl"))]
#[cfg(not(feature = "http-client-curl"))]
git_url::Protocol::Https | git_url::Protocol::Http => return Err(Error::CompiledWithoutHttp(url.protocol)),
#[cfg(feature = "http-curl")]
#[cfg(feature = "http-client-curl")]
git_url::Protocol::Https | git_url::Protocol::Http => Box::new(
crate::client::http::connect(
&url.host.as_ref().expect("host is present in url"),
Expand Down
71 changes: 70 additions & 1 deletion git-transport/src/client/http.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use quick_error::quick_error;
use std::path::Path;
use std::{io, path::Path};

quick_error! {
#[derive(Debug)]
Expand All @@ -9,6 +9,75 @@ quick_error! {
}
}
}
#[cfg(feature = "http-client-curl")]
pub(crate) mod pipe {
use std::io;

pub struct PipeWriter;
pub struct PipeReader;

impl io::Read for PipeReader {
fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> {
unimplemented!()
}
}

impl io::Write for PipeWriter {
fn write(&mut self, _buf: &[u8]) -> io::Result<usize> {
unimplemented!()
}

fn flush(&mut self) -> io::Result<()> {
unimplemented!()
}
}

pub fn _unidirectional() -> (PipeWriter, PipeReader) {
unimplemented!("unidirectional pipe")
}
}

#[cfg(feature = "http-client-curl")]
pub(crate) mod curl {
use crate::client::http::{pipe::PipeReader, Error, Http};
use curl::easy::Easy2;
use std::io::Read;

struct Handler;

impl curl::easy::Handler for Handler {}

pub struct CurlHttp {
_handle: Easy2<Handler>,
}

impl Http for CurlHttp {
type Response = PipeReader;

fn get(_url: &str, _headers: impl Iterator<Item = impl AsRef<str>>) -> Result<Self::Response, Error> {
unimplemented!()
}

fn post(
_url: &str,
_headers: impl Iterator<Item = impl AsRef<str>>,
_body: impl Read,
) -> Result<Self::Response, Error> {
unimplemented!()
}
}
}

trait Http {
type Response: io::Read;

fn get(url: &str, headers: impl Iterator<Item = impl AsRef<str>>) -> Result<Self::Response, Error>;
fn post(
url: &str,
headers: impl Iterator<Item = impl AsRef<str>>,
body: impl io::Read,
) -> Result<Self::Response, Error>;
}

pub struct Transport {}

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 @@ -5,7 +5,7 @@ use std::io;
pub mod connect;
pub mod file;
pub mod git;
#[cfg(feature = "http-curl")]
#[cfg(feature = "http-client-curl")]
pub mod http;
pub mod ssh;
#[doc(inline)]
Expand Down
3 changes: 3 additions & 0 deletions tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* [x] V1 handshake
* [ ] V2 handshake
* [ ] http://git-upload-pack
* **prerequisites**
* [ ] pipe to link writers with readers using bytes
* [ ] HTTP trait for simple gets and post implemented for Curl
* [ ] V1 handshake
* **git-refs**
* [ ] a way to know if a ref needs to be parsed (like `ref/name^{}`)
Expand Down

0 comments on commit 8351299

Please sign in to comment.