add native-tls and serde json support
This commit is contained in:
51
src/body.rs
51
src/body.rs
@@ -1,8 +1,17 @@
|
||||
use std::io::Read;
|
||||
|
||||
pub struct Body(Kind);
|
||||
pub struct Body {
|
||||
reader: Kind,
|
||||
}
|
||||
|
||||
impl Body {
|
||||
pub fn new<R: Read + 'static>(reader: R) -> Body {
|
||||
Body {
|
||||
reader: Kind::Reader(Box::new(reader), None),
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn sized(reader: (), len: u64) -> Body {
|
||||
unimplemented!()
|
||||
}
|
||||
@@ -10,17 +19,20 @@ impl Body {
|
||||
pub fn chunked(reader: ()) -> Body {
|
||||
unimplemented!()
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
enum Kind {
|
||||
Length,
|
||||
Chunked
|
||||
Reader(Box<Read>, Option<u64>),
|
||||
Bytes(Vec<u8>),
|
||||
}
|
||||
|
||||
impl From<Vec<u8>> for Body {
|
||||
#[inline]
|
||||
fn from(v: Vec<u8>) -> Body {
|
||||
unimplemented!()
|
||||
Body {
|
||||
reader: Kind::Bytes(v),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +43,34 @@ impl From<String> for Body {
|
||||
}
|
||||
}
|
||||
|
||||
/// Wraps a `std::io::Write`.
|
||||
pub struct Pipe(Kind);
|
||||
|
||||
impl<'a> From<&'a [u8]> for Body {
|
||||
#[inline]
|
||||
fn from(s: &'a [u8]) -> Body {
|
||||
s.to_vec().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a str> for Body {
|
||||
#[inline]
|
||||
fn from(s: &'a str) -> Body {
|
||||
s.as_bytes().into()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Wraps a `std::io::Write`.
|
||||
//pub struct Pipe(Kind);
|
||||
|
||||
|
||||
pub fn as_hyper_body<'a>(body: &'a Body) -> ::hyper::client::Body<'a> {
|
||||
match body.reader {
|
||||
Kind::Bytes(ref bytes) => {
|
||||
let len = bytes.len();
|
||||
::hyper::client::Body::BufBody(bytes, len)
|
||||
},
|
||||
Kind::Reader(..) => unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user