feat(lib): replace types with those from http crate
BREAKING CHANGE: `Method`, `Request`, `Response`, `StatusCode`, `Version`, and `Uri` have been replaced with types from the `http` crate. The `hyper::header` module is gone for now. Removed `Client::get`, since it needed to construct a `Request<B>` with an empty body. Just use `Client::request` instead. Removed `compat` cargo feature, and `compat` related API.
This commit is contained in:
@@ -12,9 +12,7 @@ use futures::{Future, Stream};
|
||||
use tokio_core::reactor::{Core, Handle};
|
||||
use tokio_core::net::TcpListener;
|
||||
|
||||
use hyper::client;
|
||||
use hyper::header::{ContentLength, ContentType};
|
||||
use hyper::Method;
|
||||
use hyper::{Body, Method, Request, Response};
|
||||
|
||||
|
||||
#[bench]
|
||||
@@ -30,7 +28,7 @@ fn get_one_at_a_time(b: &mut test::Bencher) {
|
||||
b.bytes = 160 * 2 + PHRASE.len() as u64;
|
||||
b.iter(move || {
|
||||
let work = client.get(url.clone()).and_then(|res| {
|
||||
res.body().for_each(|_chunk| {
|
||||
res.into_body().into_stream().for_each(|_chunk| {
|
||||
Ok(())
|
||||
})
|
||||
});
|
||||
@@ -54,12 +52,11 @@ fn post_one_at_a_time(b: &mut test::Bencher) {
|
||||
let post = "foo bar baz quux";
|
||||
b.bytes = 180 * 2 + post.len() as u64 + PHRASE.len() as u64;
|
||||
b.iter(move || {
|
||||
let mut req = client::Request::new(Method::Post, url.clone());
|
||||
req.headers_mut().set(ContentLength(post.len() as u64));
|
||||
req.set_body(post);
|
||||
|
||||
let mut req = Request::new(post.into());
|
||||
*req.method_mut() = Method::POST;
|
||||
*req.uri_mut() = url.clone();
|
||||
let work = client.request(req).and_then(|res| {
|
||||
res.body().for_each(|_chunk| {
|
||||
res.into_body().into_stream().for_each(|_chunk| {
|
||||
Ok(())
|
||||
})
|
||||
});
|
||||
@@ -71,7 +68,7 @@ fn post_one_at_a_time(b: &mut test::Bencher) {
|
||||
static PHRASE: &'static [u8] = include_bytes!("../CHANGELOG.md"); //b"Hello, World!";
|
||||
|
||||
fn spawn_hello(handle: &Handle) -> SocketAddr {
|
||||
use hyper::server::{const_service, service_fn, NewService, Request, Response};
|
||||
use hyper::server::{const_service, service_fn, NewService};
|
||||
let addr = "127.0.0.1:0".parse().unwrap();
|
||||
let listener = TcpListener::bind(&addr, handle).unwrap();
|
||||
let addr = listener.local_addr().unwrap();
|
||||
@@ -79,14 +76,12 @@ fn spawn_hello(handle: &Handle) -> SocketAddr {
|
||||
let handle2 = handle.clone();
|
||||
let http = hyper::server::Http::<hyper::Chunk>::new();
|
||||
|
||||
let service = const_service(service_fn(|req: Request| {
|
||||
req.body()
|
||||
let service = const_service(service_fn(|req: Request<Body>| {
|
||||
req.into_body()
|
||||
.into_stream()
|
||||
.concat2()
|
||||
.map(|_| {
|
||||
Response::<hyper::Body>::new()
|
||||
.with_header(ContentLength(PHRASE.len() as u64))
|
||||
.with_header(ContentType::plaintext())
|
||||
.with_body(PHRASE)
|
||||
Response::new(Body::from(PHRASE))
|
||||
})
|
||||
}));
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@ use std::io::{Read, Write};
|
||||
use std::net::{TcpListener, TcpStream};
|
||||
use std::sync::mpsc;
|
||||
|
||||
use futures::{future, stream, Future};
|
||||
use futures::{future, stream, Future, Stream};
|
||||
use futures::sync::oneshot;
|
||||
|
||||
use hyper::header::{ContentLength, ContentType, TransferEncoding};
|
||||
use hyper::server::{self, Service};
|
||||
use hyper::{Body, Request, Response};
|
||||
use hyper::server::Service;
|
||||
|
||||
macro_rules! bench_server {
|
||||
($b:ident, $header:expr, $body:expr) => ({
|
||||
@@ -65,37 +65,37 @@ fn body(b: &'static [u8]) -> hyper::Body {
|
||||
|
||||
#[bench]
|
||||
fn throughput_fixedsize_small_payload(b: &mut test::Bencher) {
|
||||
bench_server!(b, ContentLength(13), || body(b"Hello, World!"))
|
||||
bench_server!(b, ("content-length", "13"), || body(b"Hello, World!"))
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn throughput_fixedsize_large_payload(b: &mut test::Bencher) {
|
||||
bench_server!(b, ContentLength(1_000_000), || body(&[b'x'; 1_000_000]))
|
||||
bench_server!(b, ("content-length", "1000000"), || body(&[b'x'; 1_000_000]))
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn throughput_fixedsize_many_chunks(b: &mut test::Bencher) {
|
||||
bench_server!(b, ContentLength(1_000_000), || {
|
||||
bench_server!(b, ("content-length", "1000000"), || {
|
||||
static S: &'static [&'static [u8]] = &[&[b'x'; 1_000] as &[u8]; 1_000] as _;
|
||||
stream::iter_ok(S.iter())
|
||||
Body::wrap_stream(stream::iter_ok(S.iter()).map(|&s| s))
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn throughput_chunked_small_payload(b: &mut test::Bencher) {
|
||||
bench_server!(b, TransferEncoding::chunked(), || body(b"Hello, World!"))
|
||||
bench_server!(b, ("transfer-encoding", "chunked"), || body(b"Hello, World!"))
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn throughput_chunked_large_payload(b: &mut test::Bencher) {
|
||||
bench_server!(b, TransferEncoding::chunked(), || body(&[b'x'; 1_000_000]))
|
||||
bench_server!(b, ("transfer-encoding", "chunked"), || body(&[b'x'; 1_000_000]))
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn throughput_chunked_many_chunks(b: &mut test::Bencher) {
|
||||
bench_server!(b, TransferEncoding::chunked(), || {
|
||||
bench_server!(b, ("transfer-encoding", "chunked"), || {
|
||||
static S: &'static [&'static [u8]] = &[&[b'x'; 1_000] as &[u8]; 1_000] as _;
|
||||
stream::iter_ok(S.iter())
|
||||
Body::wrap_stream(stream::iter_ok(S.iter()).map(|&s| s))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -177,26 +177,26 @@ fn raw_tcp_throughput_large_payload(b: &mut test::Bencher) {
|
||||
tx.send(()).unwrap();
|
||||
}
|
||||
|
||||
struct BenchPayload<H, F> {
|
||||
header: H,
|
||||
struct BenchPayload<F> {
|
||||
header: (&'static str, &'static str),
|
||||
body: F,
|
||||
}
|
||||
|
||||
impl<H, F, B> Service for BenchPayload<H, F>
|
||||
impl<F, B> Service for BenchPayload<F>
|
||||
where
|
||||
H: hyper::header::Header + Clone,
|
||||
F: Fn() -> B,
|
||||
{
|
||||
type Request = server::Request;
|
||||
type Response = server::Response<B>;
|
||||
type Request = Request<Body>;
|
||||
type Response = Response<B>;
|
||||
type Error = hyper::Error;
|
||||
type Future = future::FutureResult<Self::Response, hyper::Error>;
|
||||
fn call(&self, _req: Self::Request) -> Self::Future {
|
||||
future::ok(
|
||||
server::Response::new()
|
||||
.with_header(self.header.clone())
|
||||
.with_header(ContentType::plaintext())
|
||||
.with_body((self.body)())
|
||||
Response::builder()
|
||||
.header(self.header.0, self.header.1)
|
||||
.header("content-type", "text/plain")
|
||||
.body((self.body)())
|
||||
.unwrap()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user