Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade hyper to v0.11 #151

Merged
merged 1 commit into from Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions .travis.yml
Expand Up @@ -4,11 +4,22 @@ matrix:
allow_failures:
- rust: nightly
include:
- rust: stable
- os: osx
rust: stable

- rust: stable
env: FEATURES=""
- rust: beta
env: FEATURES=""
- rust: nightly
env: FEATURES=""

- rust: stable
env: FEATURES="--features unstable"
- rust: beta
env: FEATURES="--features unstable"
- rust: nightly
env: FEATURES="--features unstable"

sudo: false
dist: trusty
Expand All @@ -20,8 +31,5 @@ cache:
- target/debug/build

script:
- cargo build --verbose
- cargo test --verbose

notifications:
email: false
- cargo build $FEATURES
- cargo test $FEATURES
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
117 changes: 117 additions & 0 deletions src/async_impl/body.rs
@@ -0,0 +1,117 @@
use std::fmt;

use futures::{Stream, Poll, Async};
use bytes::Bytes;

/// An asynchronous `Stream`.
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),
}
}
}


/// A chunk of bytes for a `Body`.
///
/// A `Chunk` can be treated like `&[u8]`.
#[derive(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()
}
}

impl fmt::Debug for Body {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Body")
.finish()
}
}

impl fmt::Debug for Chunk {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&self.inner, f)
}
}

// pub(crate)

#[inline]
pub fn wrap(body: ::hyper::Body) -> Body {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to make these inherent methods?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, because they're pub(crate). Implementation details.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh. I actually totally misunderstood the // pub(crate) comment. I thought it was a reminder to make these pub(crate) once that feature was stable, not to say the following pub items are not part of the public API

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),
}
}