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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
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), | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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 thesepub(crate)
once that feature was stable, not to say the followingpub
items are not part of the public API