Skip to content

Commit

Permalink
[clone] unbelievable, but it now seems to work as expected
Browse files Browse the repository at this point in the history
And I have no idea what the difference is accept that the read patterns
changed.

Let's hope this issue doesn't return or that we soon have an altenrative
HTTP(S) layer implementation that is…deterministic.

It's interesting to see that a supposedly simple interaction with a
Rust-wrapped C-library already shatters my feeling of safety and
adds a lot of time due to weirdness that really wasn't ever
a problem before.
  • Loading branch information
Byron committed Aug 22, 2020
1 parent 8250448 commit 88dbbf5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
1 change: 0 additions & 1 deletion git-transport/src/client/git/recv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub fn capabilties_and_possibly_refs<'a, T: io::Read>(
let capabilities = rd
.peek_line()
.ok_or(crate::client::Error::ExpectedLine("capabilities or version"))???;
dbg!(capabilities);
let (capabilities, delimiter_position) = Capabilities::from_bytes(
capabilities
.to_text()
Expand Down
1 change: 1 addition & 0 deletions git-transport/src/client/http/curl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl curl::easy::Handler for Handler {
}

fn header(&mut self, data: &[u8]) -> bool {
// TODO: check for HTTP status!
match self.send_header.as_mut() {
Some(writer) => writer.write_all(data).is_ok(),
None => false,
Expand Down
11 changes: 6 additions & 5 deletions git-transport/src/client/http/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::client::{git, SetServiceResponse};
use crate::{Protocol, Service};
use quick_error::quick_error;
use std::io::Read;
use std::{borrow::Cow, convert::Infallible, io};

quick_error! {
Expand Down Expand Up @@ -88,14 +89,14 @@ impl crate::client::TransportSketch for Transport {
}
let GetResponse { mut headers, mut body } =
self.http.get(&url, static_headers.iter().chain(&dynamic_headers))?;
io::copy(&mut headers, &mut io::stderr())?;
// TODO: check for Content-Type: application/x-git-upload-pack-advertisement
io::copy(&mut headers, &mut io::sink())?;

// TODO: keep it around, it's expensive
let mut rd = git_packetline::Reader::new(&mut body, None);
let _service = rd
.read_line()
.ok_or(crate::client::Error::ExpectedLine("server marker"))???; // TODO: verify this line
dbg!(_service.as_bstr());
let mut _service = String::new();
rd.as_read().read_to_string(&mut _service)?;
dbg!(_service);
let (capabilities, refs) = git::recv::capabilties_and_possibly_refs(&mut rd)?;
Ok(SetServiceResponse {
actual_protocol: Protocol::V1, // TODO
Expand Down
16 changes: 14 additions & 2 deletions git-transport/tests/client/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ impl MockServer {
stream.read_to_end(&mut out).ok();
stream.write_all(&fixture).expect("write to always work");
stream.flush().expect("flush to work");
eprintln!("flushing and done");
out
});
is_ready.recv().expect("someone sending eventually");
Expand Down Expand Up @@ -80,7 +79,20 @@ mod upload_pack {
Protocol::V1,
)?;
let _response = c.set_service(Service::UploadPack)?;
assert_eq!(&server.received_as_string(), "hello");
assert_eq!(
server.received_as_string().lines().collect::<Vec<_>>(),
format!(
"GET /path/not/important/due/to/mock/info/refs?service=git-upload-pack HTTP/1.1
Host: 127.0.0.1:{}
Accept: */*
User-Agent: git/oxide-0.1.0
",
server.addr.port()
)
.lines()
.collect::<Vec<_>>()
);
Ok(())
}
}
1 change: 1 addition & 0 deletions tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* [x] HTTP trait for simple gets and post implemented for Curl
* [ ] propagate HTTP status code
* [x] non-OK is propagated
* [ ] test for auto-reset on ReadWithProgress drop
* [ ] timeout configuration
* [ ] V1 handshake
* **git-refs**
Expand Down

0 comments on commit 88dbbf5

Please sign in to comment.