Skip to content

Commit

Permalink
[clone] First step towards http V2 handshake shows capabilities are…
Browse files Browse the repository at this point in the history
…more different than anticipated.
Needs more special handling to parse correctly and nicely.
Let's see…
  • Loading branch information
Byron committed Aug 24, 2020
1 parent 1a58955 commit f58a785
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion git-transport/src/client/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl crate::client::TransportSketch for Transport {

let (capabilities, refs) = git::recv::capabilties_and_possibly_refs(&mut self.line_reader, self.version)?;
Ok(SetServiceResponse {
actual_protocol: Protocol::V1, // TODO
actual_protocol: self.version,
capabilities,
refs,
})
Expand Down
37 changes: 36 additions & 1 deletion git-transport/tests/client/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ mod upload_pack {
use std::io::BufRead;

#[test]
fn clone_v1() -> crate::Result {
fn handshake_v1() -> crate::Result {
let (mut server, mut c) = serve_and_connect(
"v1/http-handshake.response",
"path/not/important/due/to/mock",
Expand Down Expand Up @@ -207,6 +207,41 @@ Host: 127.0.0.1:{}
Accept: */*
User-Agent: git/oxide-{}
",
server.addr.port(),
env!("CARGO_PKG_VERSION")
)
.lines()
.collect::<Vec<_>>()
);
Ok(())
}
#[test]
fn handshake_v2() -> crate::Result {
let (mut server, mut c) = serve_and_connect(
"v2/http-handshake.response",
"path/not/important/due/to/mock",
Protocol::V2,
)?;
let SetServiceResponse {
actual_protocol,
capabilities,
refs,
} = c.set_service(Service::UploadPack)?;
assert_eq!(actual_protocol, Protocol::V2);
assert!(
refs.is_none(),
"refs are only returned in V1, as V2 favors a separate command (with more options)"
);

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-{}
",
server.addr.port(),
env!("CARGO_PKG_VERSION")
Expand Down

0 comments on commit f58a785

Please sign in to comment.