diff options
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/lib.rs | 9 | ||||
-rw-r--r-- | src/rep.rs | 2 | ||||
-rw-r--r-- | src/transport.rs | 13 |
5 files changed, 20 insertions, 6 deletions
@@ -2,6 +2,7 @@ name = "shiplift" version = "0.0.1" dependencies = [ + "httparse 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "jed 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.0.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -7,6 +7,7 @@ authors = ["softprops <d.tangren@gmail.com>"] [dependencies] mime = "0.0.10" +httparse = "0.1.1" hyper = "0.3.14" jed = "0.1.0" openssl = "0.6.1" @@ -33,7 +33,7 @@ use rep::Container as ContainerRep; use rep::{ Change, ContainerDetails, ImageDetails, Info, SearchResult, Top, Version }; -use std::env; +use std::env::{ self, VarError }; use std::path::Path; use std::io::{ Read, Result }; use transport::{ Body, Transport }; @@ -79,6 +79,7 @@ impl<'a> Images<'a> { pub fn list(self) -> Result<Vec<ImageRep>> { let raw = try!(self.docker.get("/images/json")); + println!("raw {:?}", raw); Ok(json::decode::<Vec<ImageRep>>(&raw).unwrap()) } @@ -203,11 +204,13 @@ impl<'a> Containers<'a> { // https://docs.docker.com/reference/api/docker_remote_api_v1.17/ impl Docker { pub fn new() -> Docker { + let fallback: std::result::Result<String, VarError> = Ok("unix:///var/run/docker.sock".to_string()); let host = env::var("DOCKER_HOST") + .or(fallback) .map(|h| Url::parse(&h).ok() .expect("invalid url")) - .ok() - .expect("expected host"); + .ok() + .expect("expected host"); let domain = match host.scheme_data { SchemeData::NonRelative(s) => s, SchemeData::Relative(RelativeSchemeData { host: host, .. }) => @@ -15,7 +15,7 @@ pub struct Image { pub ParentId: String, //pub Labels: ???, pub RepoTags: Vec<String>, - pub RepoDigests: Vec<String>, + pub RepoDigests: Option<Vec<String>>, pub Size: u64, pub VirtualSize: u64 } diff --git a/src/transport.rs b/src/transport.rs index e340067..c2c621e 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -5,6 +5,9 @@ extern crate unix_socket; use std::ops::DerefMut; use hyper::Client; use hyper::client; +use self::hyper::buffer::BufReader; +use self::hyper::http::{ parse_response }; +use self::hyper::http::HttpReader::{ ChunkedReader, EofReader }; use self::hyper::header::{ ContentType, qitem }; use hyper::method::Method; use self::mime::{ Attr, Mime, Value }; @@ -50,8 +53,14 @@ impl Transport for UnixStream { }; let req = format!("{} {} HTTP/1.0\r\n\r\n", method_str, endpoint); try!(self.write_all(req.as_bytes())); - let clone = try!(self.try_clone()); - Ok(Box::new(clone)) + // read the body -- https://github.com/hyperium/hyper/blob/06d072bca1b4af3507af370cbd0ca2ac8f64fc00/src/client/response.rs#L36-L74 + let cloned = try!(self.try_clone()); + let mut stream = BufReader::new(cloned); + let head = parse_response(&mut stream).unwrap(); + let headers = head.headers; + println!("parsed {:?}", headers); + println!("sending clone"); + Ok(Box::new(ChunkedReader(stream, None))) } } |