Skip to content

Commit

Permalink
[ref-ls] Finally fix http content encoding (and fixtures to go with it)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Sep 5, 2020
1 parent 24ebc59 commit 49b7ad9
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 50 deletions.
47 changes: 0 additions & 47 deletions git-transport/src/client/http/curl/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,55 +40,10 @@ impl Handler {
}
}

mod chunks {
pub struct Iter<'a> {
data: &'a [u8],
}

impl<'a> Iterator for Iter<'a> {
type Item = &'a [u8];

fn next(&mut self) -> Option<Self::Item> {
unimplemented!()
}
}

pub fn iter(data: &[u8]) -> Iter {
Iter { data }
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn iteration_without_trailer() {
assert_eq!(
iter(b"1e\r\n001e# service=git-upload-pack\n\r\n4\r\n0000\r\n").collect::<Vec<_>>(),
vec![&b"001e# service=git-upload-pack\n"[..], b"0000"]
);
}

#[test]
fn zero_trailing_buffer() {
assert_eq!(iter(b"0\r\n\r\n").collect::<Vec<_>>(), vec![&b""[..]]);
}
}
}

impl curl::easy::Handler for Handler {
fn write(&mut self, data: &[u8]) -> Result<usize, curl::easy::WriteError> {
drop(self.send_header.take()); // signal header readers to stop trying
match self.send_data.as_mut() {
// Some(writer) => {
// // when testing, we don't actually have chunks
// for chunk in chunks::iter(data) {
// if let Err(_) = writer.write_all(chunk) {
// return Ok(0);
// }
// }
// Ok(data.len())
// }
Some(writer) => writer.write_all(data).map(|_| data.len()).or_else(|_| Ok(0)),
None => Ok(0), // nothing more to receive, reader is done
}
Expand Down Expand Up @@ -160,8 +115,6 @@ pub fn new() -> (
handle.post(upload)?;
handle.http_headers(headers)?;
handle.transfer_encoding(false)?;
// handle.http_transfer_decoding(false)?;
// handle.http_content_decoding(false)?;
handle.connect_timeout(Duration::from_secs(20))?;
let low_bytes_per_second = 1024;
handle.low_speed_limit(low_bytes_per_second)?;
Expand Down
Binary file modified git-transport/tests/fixtures/v1/http-clone.response
Binary file not shown.
Binary file modified git-transport/tests/fixtures/v1/http-handshake.response
Binary file not shown.
Binary file modified git-transport/tests/fixtures/v2/http-fetch.response
Binary file not shown.
4 changes: 2 additions & 2 deletions git-transport/tests/fixtures/v2/http-handshake.response
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
HTTP/1.1 200 OK
Server: GitHub Babel 2.0
Content-Type: application/x-git-upload-pack-advertisement
Transfer-Encoding: chunked
Content-Length: 1000
Expires: Fri, 01 Jan 1980 00:00:00 GMT
Pragma: no-cache
Cache-Control: no-cache, max-age=0, must-revalidate
Expand All @@ -15,4 +15,4 @@ X-GitHub-Request-Id: 737D:544E:C932CB:113F404:5F3F3EE5
000cls-refs
0019fetch=shallow filter
0012server-option
0000
0000
2 changes: 1 addition & 1 deletion git-transport/tests/fixtures/v2/http-lsrefs.response
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
HTTP/1.1 200 OK
Server: GitHub Babel 2.0
Content-Type: application/x-git-upload-pack-result
Transfer-Encoding: chunked
Content-Length: 4000
Expires: Fri, 01 Jan 1980 00:00:00 GMT
Pragma: no-cache
Cache-Control: no-cache, max-age=0, must-revalidate
Expand Down

0 comments on commit 49b7ad9

Please sign in to comment.