Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 25, 2020
1 parent 2e68315 commit 3738897
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
20 changes: 10 additions & 10 deletions git-transport/src/client/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@ mod traits;
pub use traits::{Error, GetResponse, Http, PostResponse};

#[cfg(feature = "http-client-curl")]
type HttpImpl = curl::Curl;
pub type Impl = curl::Curl;

pub struct Transport {
pub struct Transport<H: Http> {
url: String,
user_agent_header: &'static str,
version: crate::Protocol,
http: HttpImpl,
http: H,
service: Option<Service>,
line_reader: git_packetline::Reader<pipe::Reader>,
line_writer: git_packetline::Writer<pipe::Writer>,
line_reader: git_packetline::Reader<H::ResponseBody>,
line_writer: git_packetline::Writer<H::PostBody>,
}

impl Transport {
impl Transport<Impl> {
pub fn new(url: &str, version: crate::Protocol) -> Self {
let dummy = pipe::unidirectional(0);
Transport {
url: url.to_owned(),
user_agent_header: concat!("User-Agent: git/oxide-", env!("CARGO_PKG_VERSION")),
version,
service: None,
http: HttpImpl::new(),
http: Impl::new(),
line_reader: git_packetline::Reader::new(dummy.1, None),
line_writer: git_packetline::Writer::new(dummy.0),
}
}
}

impl client::Transport for Transport {}
impl<H: Http> client::Transport for Transport<H> {}

fn append_url(base: &str, suffix: &str) -> String {
if base.ends_with('/') {
Expand All @@ -50,7 +50,7 @@ fn append_url(base: &str, suffix: &str) -> String {
}
}

impl client::TransportSketch for Transport {
impl<H: Http> client::TransportSketch for Transport<H> {
fn handshake(&mut self, service: Service) -> Result<client::SetServiceResponse, client::Error> {
let url = append_url(&self.url, &format!("info/refs?service={}", service.as_str()));
let static_headers = [Cow::Borrowed(self.user_agent_header)];
Expand Down Expand Up @@ -113,6 +113,6 @@ impl client::TransportSketch for Transport {
}
}

pub fn connect(url: &str, version: crate::Protocol) -> Result<Transport, Infallible> {
pub fn connect(url: &str, version: crate::Protocol) -> Result<Transport<Impl>, Infallible> {
Ok(Transport::new(url, version))
}
8 changes: 7 additions & 1 deletion git-transport/tests/client/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ fn serve_and_connect(
name: &str,
path: &str,
version: Protocol,
) -> Result<(MockServer, git_transport::client::http::Transport), crate::Error> {
) -> Result<
(
MockServer,
git_transport::client::http::Transport<git_transport::client::http::Impl>,
),
crate::Error,
> {
let server = serve_once(name);
let client = git_transport::client::http::connect(
&format!(
Expand Down

0 comments on commit 3738897

Please sign in to comment.