feat(lib): redesign API to use Futures and Tokio
There are many changes involved with this, but let's just talk about
user-facing changes.
- Creating a `Client` and `Server` now needs a Tokio `Core` event loop
to attach to.
- `Request` and `Response` both no longer implement the
`std::io::{Read,Write}` traits, but instead represent their bodies as a
`futures::Stream` of items, where each item is a `Chunk`.
- The `Client.request` method now takes a `Request`, instead of being
used as a builder, and returns a `Future` that resolves to `Response`.
- The `Handler` trait for servers is no more, and instead the Tokio
`Service` trait is used. This allows interoperability with generic
middleware.
BREAKING CHANGE: A big sweeping set of breaking changes.
This commit is contained in:
@@ -19,7 +19,7 @@ header! {
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use hyper::header::{Headers, AccessControlAllowMethods};
|
||||
/// use hyper::method::Method;
|
||||
/// use hyper::Method;
|
||||
///
|
||||
/// let mut headers = Headers::new();
|
||||
/// headers.set(
|
||||
@@ -28,7 +28,7 @@ header! {
|
||||
/// ```
|
||||
/// ```
|
||||
/// use hyper::header::{Headers, AccessControlAllowMethods};
|
||||
/// use hyper::method::Method;
|
||||
/// use hyper::Method;
|
||||
///
|
||||
/// let mut headers = Headers::new();
|
||||
/// headers.set(
|
||||
|
||||
@@ -17,7 +17,7 @@ header! {
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use hyper::header::{Headers, AccessControlRequestMethod};
|
||||
/// use hyper::method::Method;
|
||||
/// use hyper::Method;
|
||||
///
|
||||
/// let mut headers = Headers::new();
|
||||
/// headers.set(AccessControlRequestMethod(Method::Get));
|
||||
|
||||
@@ -21,7 +21,7 @@ header! {
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use hyper::header::{Headers, Allow};
|
||||
/// use hyper::method::Method;
|
||||
/// use hyper::Method;
|
||||
///
|
||||
/// let mut headers = Headers::new();
|
||||
/// headers.set(
|
||||
@@ -30,7 +30,7 @@ header! {
|
||||
/// ```
|
||||
/// ```
|
||||
/// use hyper::header::{Headers, Allow};
|
||||
/// use hyper::method::Method;
|
||||
/// use hyper::Method;
|
||||
///
|
||||
/// let mut headers = Headers::new();
|
||||
/// headers.set(
|
||||
|
||||
@@ -72,7 +72,6 @@ impl fmt::Display for ContentLength {
|
||||
}
|
||||
|
||||
__hyper__deref!(ContentLength => u64);
|
||||
__hyper_generate_header_serialization!(ContentLength);
|
||||
|
||||
__hyper__tm!(ContentLength, tests {
|
||||
// Testcase from RFC
|
||||
|
||||
@@ -182,31 +182,6 @@ macro_rules! test_header {
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __hyper_generate_header_serialization {
|
||||
($id:ident) => {
|
||||
#[cfg(feature = "serde-serialization")]
|
||||
impl ::serde::Serialize for $id {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
where S: ::serde::Serializer {
|
||||
format!("{}", self).serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde-serialization")]
|
||||
impl ::serde::Deserialize for $id {
|
||||
fn deserialize<D>(deserializer: &mut D) -> Result<$id, D::Error>
|
||||
where D: ::serde::Deserializer {
|
||||
let string_representation: String =
|
||||
try!(::serde::Deserialize::deserialize(deserializer));
|
||||
let raw = string_representation.into_bytes().into();
|
||||
Ok($crate::header::Header::parse_header(&raw).unwrap())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! header {
|
||||
// $a:meta: Attributes associated with the header item (usually docs)
|
||||
@@ -238,8 +213,6 @@ macro_rules! header {
|
||||
self.fmt_header(f)
|
||||
}
|
||||
}
|
||||
|
||||
__hyper_generate_header_serialization!($id);
|
||||
};
|
||||
// List header, one or more items
|
||||
($(#[$a:meta])*($id:ident, $n:expr) => ($item:ty)+) => {
|
||||
@@ -265,7 +238,6 @@ macro_rules! header {
|
||||
self.fmt_header(f)
|
||||
}
|
||||
}
|
||||
__hyper_generate_header_serialization!($id);
|
||||
};
|
||||
// Single value header
|
||||
($(#[$a:meta])*($id:ident, $n:expr) => [$value:ty]) => {
|
||||
@@ -290,7 +262,6 @@ macro_rules! header {
|
||||
::std::fmt::Display::fmt(&**self, f)
|
||||
}
|
||||
}
|
||||
__hyper_generate_header_serialization!($id);
|
||||
};
|
||||
// List header, one or more items with "*" option
|
||||
($(#[$a:meta])*($id:ident, $n:expr) => {Any / ($item:ty)+}) => {
|
||||
@@ -330,7 +301,6 @@ macro_rules! header {
|
||||
self.fmt_header(f)
|
||||
}
|
||||
}
|
||||
__hyper_generate_header_serialization!($id);
|
||||
};
|
||||
|
||||
// optional test module
|
||||
@@ -421,4 +391,4 @@ mod transfer_encoding;
|
||||
mod upgrade;
|
||||
mod user_agent;
|
||||
mod vary;
|
||||
mod warning;
|
||||
mod warning;
|
||||
|
||||
@@ -85,11 +85,6 @@ use unicase::UniCase;
|
||||
|
||||
use self::internals::{Item, VecMap, Entry};
|
||||
|
||||
#[cfg(feature = "serde-serialization")]
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
#[cfg(feature = "serde-serialization")]
|
||||
use serde::de;
|
||||
|
||||
pub use self::shared::*;
|
||||
pub use self::common::*;
|
||||
pub use self::raw::Raw;
|
||||
@@ -437,44 +432,6 @@ impl fmt::Debug for Headers {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde-serialization")]
|
||||
impl Serialize for Headers {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
where S: Serializer
|
||||
{
|
||||
let mut state = try!(serializer.serialize_map(Some(self.len())));
|
||||
for header in self.iter() {
|
||||
try!(serializer.serialize_map_key(&mut state, header.name()));
|
||||
try!(serializer.serialize_map_value(&mut state, header.value_string()));
|
||||
}
|
||||
serializer.serialize_map_end(state)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde-serialization")]
|
||||
impl Deserialize for Headers {
|
||||
fn deserialize<D>(deserializer: &mut D) -> Result<Headers, D::Error> where D: Deserializer {
|
||||
struct HeadersVisitor;
|
||||
|
||||
impl de::Visitor for HeadersVisitor {
|
||||
type Value = Headers;
|
||||
|
||||
fn visit_map<V>(&mut self, mut visitor: V) -> Result<Headers, V::Error>
|
||||
where V: de::MapVisitor {
|
||||
let mut result = Headers::new();
|
||||
while let Some((key, value)) = try!(visitor.visit()) {
|
||||
let (key, value): (String, String) = (key, value);
|
||||
result.set_raw(key, vec![value.into_bytes()]);
|
||||
}
|
||||
try!(visitor.end());
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_map(HeadersVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
/// An `Iterator` over the fields in a `Headers` map.
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub struct HeadersItems<'a> {
|
||||
|
||||
Reference in New Issue
Block a user