summaryrefslogtreecommitdiffstats
path: root/src/transport.rs
diff options
context:
space:
mode:
authorsoftprops <d.tangren@gmail.com>2016-01-15 01:21:43 -0500
committersoftprops <d.tangren@gmail.com>2016-01-15 01:21:43 -0500
commit89740ae3c4ece331d8dbb731de14d60ee7f8a0b5 (patch)
tree1a00cc4206ef77b4eed81dbf2b1bb44f2f3529ee /src/transport.rs
parentf787799b984c8c917f76723127480627170d3fa9 (diff)
wip for image building
Diffstat (limited to 'src/transport.rs')
-rw-r--r--src/transport.rs29
1 files changed, 8 insertions, 21 deletions
diff --git a/src/transport.rs b/src/transport.rs
index dcc70d2..c035fa5 100644
--- a/src/transport.rs
+++ b/src/transport.rs
@@ -5,6 +5,7 @@ extern crate mime;
use hyper::Client;
use hyper::client;
+use hyper::client::Body;
use self::super::{Error, Result};
use self::hyper::buffer::BufReader;
use self::hyper::header::ContentType;
@@ -40,7 +41,7 @@ impl fmt::Debug for Transport {
}
impl Transport {
- pub fn request(&self, method: Method, endpoint: &str, body: Option<Body>) -> Result<String> {
+ pub fn request<'a, B>(&'a self, method: Method, endpoint: &str, body: Option<B>) -> Result<String> where B: Into<Body<'a>> {
let mut res = match self.stream(method, endpoint, body) {
Ok(r) => r,
Err(e) => panic!("failed request {:?}", e),
@@ -51,7 +52,9 @@ impl Transport {
Ok(body)
}
- pub fn stream(&self, method: Method, endpoint: &str, body: Option<Body>) -> Result<Box<Read>> {
+ pub fn stream<'c, B>(
+ &'c self, method: Method, endpoint: &str, body: Option<B>
+ ) -> Result<Box<Read>> where B: Into<Body<'c>> {
let req = match *self {
Transport::Tcp { ref client, ref host } => {
client.request(method, &format!("{}{}", host, endpoint)[..])
@@ -62,9 +65,9 @@ impl Transport {
};
let embodied = match body {
- Some(Body { read: r, size: l }) => {
- let reader: &mut Read = *r.deref_mut();
- req.header(ContentType::json()).body(client::Body::SizedBody(reader, l))
+ Some(b) => {//Body { read: r, size: l }) => {
+ //let reader: &mut Read = *r.deref_mut();
+ req.header(ContentType::json()).body(b)//client::Body::SizedBody(reader, l))
}
_ => req,
};
@@ -109,19 +112,3 @@ impl Transport {
}
}
}
-
-#[doc(hidden)]
-pub struct Body<'a> {
- read: &'a mut Box<&'a mut Read>,
- size: u64,
-}
-
-impl<'a> Body<'a> {
- /// Create a new body instance
- pub fn new(read: &'a mut Box<&'a mut Read>, size: u64) -> Body<'a> {
- Body {
- read: read,
- size: size,
- }
- }
-}