Skip to content

Commit

Permalink
upgrade hyper to v0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Jun 20, 2017
1 parent 8633060 commit 023a149
Show file tree
Hide file tree
Showing 19 changed files with 1,732 additions and 579 deletions.
24 changes: 20 additions & 4 deletions Cargo.toml
Expand Up @@ -10,17 +10,33 @@ license = "MIT/Apache-2.0"
categories = ["web-programming::http-client"]

[dependencies]
hyper = "0.10.12"
hyper-native-tls = "0.2.4"
libc = "0.2"
bytes = "0.4"
futures = "0.1.14"
hyper = "0.11"
hyper-tls = "0.1"
libflate = "0.1.5"
log = "0.3"
native-tls = "0.1"
serde = "1.0"
serde_json = "1.0"
serde_urlencoded = "0.5"
tokio-core = "0.1.6"
url = "1.2"
libflate = "0.1.5"

[dev-dependencies]
env_logger = "0.4"
serde_derive = "1.0"
error-chain = "0.10"

[features]
unstable = []


[[example]]
name = "simple"
path = "examples/simple.rs"

[[example]]
name = "async"
path = "examples/async.rs"
required-features = ["unstable"]
16 changes: 16 additions & 0 deletions examples/async.rs
@@ -0,0 +1,16 @@
extern crate futures;
extern crate reqwest;
extern crate tokio_core;

use futures::Future;

fn main() {
let mut core = tokio_core::reactor::Core::new().unwrap();
let client = reqwest::unstable::async::Client::new(&core.handle()).unwrap();

let work = client.get("https://hyper.rs").unwrap().send().map(|res| {
println!("{}", res.status());
});

core.run(work).unwrap();
}
26 changes: 0 additions & 26 deletions examples/response_json.rs

This file was deleted.

2 changes: 1 addition & 1 deletion examples/simple.rs
Expand Up @@ -16,7 +16,7 @@ fn run() -> Result<()> {

println!("GET https://www.rust-lang.org");

let mut res = reqwest::get("https://www.rust-lang.org")?;
let mut res = reqwest::get("https://www.rust-lang.org/en-US/")?;

println!("Status: {}", res.status());
println!("Headers:\n{}", res.headers());
Expand Down
98 changes: 98 additions & 0 deletions src/async_impl/body.rs
@@ -0,0 +1,98 @@
use futures::{Stream, Poll, Async};
use bytes::Bytes;

pub struct Body {
inner: Inner,
}

enum Inner {
Reusable(Bytes),
Hyper(::hyper::Body),
}

impl Body {
fn poll_inner(&mut self) -> &mut ::hyper::Body {
match self.inner {
Inner::Hyper(ref mut body) => body,
Inner::Reusable(_) => unreachable!(),
}
}
}

impl Stream for Body {
type Item = Chunk;
type Error = ::Error;

#[inline]
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
match try_!(self.poll_inner().poll()) {
Async::Ready(opt) => Ok(Async::Ready(opt.map(|chunk| Chunk {
inner: chunk,
}))),
Async::NotReady => Ok(Async::NotReady),
}
}
}


#[derive(Debug, Default)]
pub struct Chunk {
inner: ::hyper::Chunk,
}

impl ::std::ops::Deref for Chunk {
type Target = [u8];
#[inline]
fn deref(&self) -> &Self::Target {
self.inner.as_ref()
}
}

impl Extend<u8> for Chunk {
fn extend<T>(&mut self, iter: T)
where T: IntoIterator<Item=u8> {
self.inner.extend(iter)
}
}

impl IntoIterator for Chunk {
type Item = u8;
//XXX: exposing type from hyper!
type IntoIter = <::hyper::Chunk as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
self.inner.into_iter()
}
}

// pub(crate)

#[inline]
pub fn wrap(body: ::hyper::Body) -> Body {
Body {
inner: Inner::Hyper(body),
}
}

#[inline]
pub fn take(body: &mut Body) -> Body {
use std::mem;
let inner = mem::replace(&mut body.inner, Inner::Hyper(::hyper::Body::empty()));
Body {
inner: inner,
}
}

#[inline]
pub fn reusable(chunk: Bytes) -> Body {
Body {
inner: Inner::Reusable(chunk),
}
}

#[inline]
pub fn into_hyper(body: Body) -> (Option<Bytes>, ::hyper::Body) {
match body.inner {
Inner::Reusable(chunk) => (Some(chunk.clone()), chunk.into()),
Inner::Hyper(b) => (None, b),
}
}

0 comments on commit 023a149

Please sign in to comment.