summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--Cargo.toml1
-rw-r--r--src/lib.rs9
-rw-r--r--src/rep.rs2
-rw-r--r--src/transport.rs13
5 files changed, 20 insertions, 6 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 8794532..b55e997 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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)",
diff --git a/Cargo.toml b/Cargo.toml
index 99abf0c..57f169b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"
diff --git a/src/lib.rs b/src/lib.rs
index 3db99da..7f9bd4f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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, .. }) =>
diff --git a/src/rep.rs b/src/rep.rs
index 74bfe41..15e1021 100644
--- a/src/rep.rs
+++ b/src/rep.rs
@@ -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)))
}
}