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:
Sean McArthur
2018-02-28 16:37:17 -08:00
parent a37e6b59e6
commit 3cd48b45fb
109 changed files with 1004 additions and 14411 deletions

View File

@@ -11,8 +11,7 @@ use std::net::TcpListener;
use std::thread;
use std::time::Duration;
use hyper::client::{Client, Request};
use hyper::{Method, StatusCode};
use hyper::{Body, Client, Method, Request, StatusCode};
use futures::{Future, Stream};
use futures::sync::oneshot;
@@ -33,13 +32,13 @@ macro_rules! test {
request:
method: $client_method:ident,
url: $client_url:expr,
headers: [ $($request_headers:expr,)* ],
headers: { $($request_header_name:expr => $request_header_val:expr,)* },
body: $request_body:expr,
proxy: $request_proxy:expr,
response:
status: $client_status:ident,
headers: [ $($response_headers:expr,)* ],
headers: { $($response_header_name:expr => $response_header_val:expr,)* },
body: $response_body:expr,
) => (
test! {
@@ -52,13 +51,13 @@ macro_rules! test {
request:
method: $client_method,
url: $client_url,
headers: [ $($request_headers,)* ],
headers: { $($request_header_name => $request_header_val,)* },
body: $request_body,
proxy: $request_proxy,
response:
status: $client_status,
headers: [ $($response_headers,)* ],
headers: { $($response_header_name => $response_header_val,)* },
body: $response_body,
}
);
@@ -72,19 +71,17 @@ macro_rules! test {
request:
method: $client_method:ident,
url: $client_url:expr,
headers: [ $($request_headers:expr,)* ],
headers: { $($request_header_name:expr => $request_header_val:expr,)* },
body: $request_body:expr,
proxy: $request_proxy:expr,
response:
status: $client_status:ident,
headers: [ $($response_headers:expr,)* ],
headers: { $($response_header_name:expr => $response_header_val:expr,)* },
body: $response_body:expr,
) => (
#[test]
fn $name() {
#![allow(unused)]
use hyper::header::*;
let _ = pretty_env_logger::try_init();
let mut core = Core::new().unwrap();
@@ -100,7 +97,7 @@ macro_rules! test {
request:
method: $client_method,
url: $client_url,
headers: [ $($request_headers,)* ],
headers: { $($request_header_name => $request_header_val,)* },
body: $request_body,
proxy: $request_proxy,
}.unwrap();
@@ -108,10 +105,10 @@ macro_rules! test {
assert_eq!(res.status(), StatusCode::$client_status);
$(
assert_eq!(res.headers().get(), Some(&$response_headers));
assert_eq!(res.headers()[$response_header_name], $response_header_val);
)*
let body = core.run(res.body().concat2()).unwrap();
let body = core.run(res.into_parts().1.concat2()).unwrap();
let expected_res_body = Option::<&[u8]>::from($response_body)
.unwrap_or_default();
@@ -127,7 +124,7 @@ macro_rules! test {
request:
method: $client_method:ident,
url: $client_url:expr,
headers: [ $($request_headers:expr,)* ],
headers: { $($request_header_name:expr => $request_header_val:expr,)* },
body: $request_body:expr,
proxy: $request_proxy:expr,
@@ -135,8 +132,6 @@ macro_rules! test {
) => (
#[test]
fn $name() {
#![allow(unused)]
use hyper::header::*;
let _ = pretty_env_logger::try_init();
let mut core = Core::new().unwrap();
@@ -152,7 +147,7 @@ macro_rules! test {
request:
method: $client_method,
url: $client_url,
headers: [ $($request_headers,)* ],
headers: { $($request_header_name => $request_header_val,)* },
body: $request_body,
proxy: $request_proxy,
}.unwrap_err();
@@ -174,29 +169,45 @@ macro_rules! test {
request:
method: $client_method:ident,
url: $client_url:expr,
headers: [ $($request_headers:expr,)* ],
headers: { $($request_header_name:expr => $request_header_val:expr,)* },
body: $request_body:expr,
proxy: $request_proxy:expr,
) => ({
let server = TcpListener::bind("127.0.0.1:0").unwrap();
let addr = server.local_addr().unwrap();
let mut core = $core;
let core = $core;
let mut config = Client::configure();
if !$set_host {
config = config.set_host(false);
}
let client = config.build(&core.handle());
let mut req = Request::new(Method::$client_method, format!($client_url, addr=addr).parse().unwrap());
$(
req.headers_mut().set($request_headers);
)*
if let Some(body) = $request_body {
let mut is_empty = false;
let body = if let Some(body) = $request_body {
let body: &'static str = body;
req.set_body(body);
body.into()
} else {
is_empty = true;
Body::empty()
};
let mut req = Request::builder();
req
.method(Method::$client_method)
$(
.header($request_header_name, $request_header_val)
)*
.uri(&*format!($client_url, addr=addr));
//TODO: remove when client bodies are fixed
if is_empty {
req.header("content-length", "0");
}
req.set_proxy($request_proxy);
let req = req.body(body)
.unwrap();
// req.set_proxy($request_proxy);
let res = client.request(req);
@@ -237,21 +248,21 @@ test! {
name: client_get,
server:
expected: "GET / HTTP/1.1\r\nHost: {addr}\r\n\r\n",
expected: "GET / HTTP/1.1\r\nhost: {addr}\r\n\r\n",
reply: REPLY_OK,
client:
request:
method: Get,
method: GET,
url: "http://{addr}/",
headers: [],
headers: {},
body: None,
proxy: false,
response:
status: Ok,
headers: [
ContentLength(0),
],
status: OK,
headers: {
"Content-Length" => "0",
},
body: None,
}
@@ -259,21 +270,21 @@ test! {
name: client_get_query,
server:
expected: "GET /foo?key=val HTTP/1.1\r\nHost: {addr}\r\n\r\n",
expected: "GET /foo?key=val HTTP/1.1\r\nhost: {addr}\r\n\r\n",
reply: REPLY_OK,
client:
request:
method: Get,
method: GET,
url: "http://{addr}/foo?key=val#dont_send_me",
headers: [],
headers: {},
body: None,
proxy: false,
response:
status: Ok,
headers: [
ContentLength(0),
],
status: OK,
headers: {
"Content-Length" => "0",
},
body: None,
}
@@ -281,21 +292,21 @@ test! {
name: client_get_implicitly_empty,
server:
expected: "GET / HTTP/1.1\r\nHost: {addr}\r\n\r\n",
expected: "GET / HTTP/1.1\r\nhost: {addr}\r\n\r\n",
reply: REPLY_OK,
client:
request:
method: Get,
method: GET,
url: "http://{addr}/",
headers: [],
headers: {},
body: Some(""),
proxy: false,
response:
status: Ok,
headers: [
ContentLength(0),
],
status: OK,
headers: {
"Content-Length" => "0",
},
body: None,
}
@@ -305,8 +316,8 @@ test! {
server:
expected: "\
POST /length HTTP/1.1\r\n\
Host: {addr}\r\n\
Content-Length: 7\r\n\
content-length: 7\r\n\
host: {addr}\r\n\
\r\n\
foo bar\
",
@@ -314,16 +325,16 @@ test! {
client:
request:
method: Post,
method: POST,
url: "http://{addr}/length",
headers: [
ContentLength(7),
],
headers: {
"Content-Length" => "7",
},
body: Some("foo bar"),
proxy: false,
response:
status: Ok,
headers: [],
status: OK,
headers: {},
body: None,
}
@@ -333,8 +344,8 @@ test! {
server:
expected: "\
POST /chunks HTTP/1.1\r\n\
Host: {addr}\r\n\
Transfer-Encoding: chunked\r\n\
transfer-encoding: chunked\r\n\
host: {addr}\r\n\
\r\n\
B\r\n\
foo bar baz\r\n\
@@ -344,16 +355,16 @@ test! {
client:
request:
method: Post,
method: POST,
url: "http://{addr}/chunks",
headers: [
TransferEncoding::chunked(),
],
headers: {
"Transfer-Encoding" => "chunked",
},
body: Some("foo bar baz"),
proxy: false,
response:
status: Ok,
headers: [],
status: OK,
headers: {},
body: None,
}
@@ -363,24 +374,24 @@ test! {
server:
expected: "\
POST /empty HTTP/1.1\r\n\
Host: {addr}\r\n\
Content-Length: 0\r\n\
content-length: 0\r\n\
host: {addr}\r\n\
\r\n\
",
reply: REPLY_OK,
client:
request:
method: Post,
method: POST,
url: "http://{addr}/empty",
headers: [
ContentLength(0),
],
headers: {
"Content-Length" => "0",
},
body: Some(""),
proxy: false,
response:
status: Ok,
headers: [],
status: OK,
headers: {},
body: None,
}
@@ -390,21 +401,21 @@ test! {
server:
expected: "\
GET http://{addr}/proxy HTTP/1.1\r\n\
Host: {addr}\r\n\
host: {addr}\r\n\
\r\n\
",
reply: REPLY_OK,
client:
request:
method: Get,
method: GET,
url: "http://{addr}/proxy",
headers: [],
headers: {},
body: None,
proxy: true,
response:
status: Ok,
headers: [],
status: OK,
headers: {},
body: None,
}
@@ -415,26 +426,26 @@ test! {
server:
expected: "\
HEAD /head HTTP/1.1\r\n\
Host: {addr}\r\n\
host: {addr}\r\n\
\r\n\
",
reply: "\
HTTP/1.1 200 OK\r\n\
Content-Length: 11\r\n\
content-Length: 11\r\n\
\r\n\
Hello World\
",
client:
request:
method: Head,
method: HEAD,
url: "http://{addr}/head",
headers: [],
headers: {},
body: None,
proxy: false,
response:
status: Ok,
headers: [],
status: OK,
headers: {},
body: None,
}
@@ -444,7 +455,7 @@ test! {
server:
expected: "\
GET /pipe HTTP/1.1\r\n\
Host: {addr}\r\n\
host: {addr}\r\n\
\r\n\
",
reply: "\
@@ -458,14 +469,14 @@ test! {
client:
request:
method: Get,
method: GET,
url: "http://{addr}/pipe",
headers: [],
headers: {},
body: None,
proxy: false,
response:
status: Ok,
headers: [],
status: OK,
headers: {},
body: None,
}
@@ -476,7 +487,7 @@ test! {
server:
expected: "\
GET /err HTTP/1.1\r\n\
Host: {addr}\r\n\
host: {addr}\r\n\
\r\n\
",
reply: "\
@@ -485,9 +496,9 @@ test! {
client:
request:
method: Get,
method: GET,
url: "http://{addr}/err",
headers: [],
headers: {},
body: None,
proxy: false,
error: |err| match err {
@@ -502,7 +513,7 @@ test! {
server:
expected: "\
GET /err HTTP/1.1\r\n\
Host: {addr}\r\n\
host: {addr}\r\n\
\r\n\
",
reply: "\
@@ -512,9 +523,9 @@ test! {
client:
request:
method: Get,
method: GET,
url: "http://{addr}/err",
headers: [],
headers: {},
body: None,
proxy: false,
error: |err| match err {
@@ -530,8 +541,8 @@ test! {
server:
expected: "\
POST /continue HTTP/1.1\r\n\
Host: {addr}\r\n\
Content-Length: 7\r\n\
content-length: 7\r\n\
host: {addr}\r\n\
\r\n\
foo bar\
",
@@ -545,16 +556,16 @@ test! {
client:
request:
method: Post,
method: POST,
url: "http://{addr}/continue",
headers: [
ContentLength(7),
],
headers: {
"Content-Length" => "7",
},
body: Some("foo bar"),
proxy: false,
response:
status: Ok,
headers: [],
status: OK,
headers: {},
body: None,
}
@@ -565,7 +576,7 @@ test! {
server:
expected: "\
GET /upgrade HTTP/1.1\r\n\
Host: {addr}\r\n\
host: {addr}\r\n\
\r\n\
",
reply: "\
@@ -577,9 +588,9 @@ test! {
client:
request:
method: Get,
method: GET,
url: "http://{addr}/upgrade",
headers: [],
headers: {},
body: None,
proxy: false,
error: |err| match err {
@@ -603,9 +614,9 @@ test! {
client:
request:
method: Connect,
method: CONNECT,
url: "http://{addr}/",
headers: [],
headers: {},
body: None,
proxy: false,
error: |err| match err {
@@ -633,18 +644,17 @@ test! {
client:
set_host: false,
request:
method: Get,
method: GET,
url: "http://{addr}/no-host/{addr}",
headers: [],
headers: {},
body: None,
proxy: false,
response:
status: Ok,
headers: [],
status: OK,
headers: {},
body: None,
}
mod dispatch_impl {
use super::*;
use std::io::{self, Read, Write};
@@ -694,10 +704,12 @@ mod dispatch_impl {
let _ = tx1.send(());
});
let uri = format!("http://{}/a", addr).parse().unwrap();
let res = client.get(uri).and_then(move |res| {
assert_eq!(res.status(), hyper::StatusCode::Ok);
let req = Request::builder()
.uri(&*format!("http://{}/a", addr))
.body(Body::empty())
.unwrap();
let res = client.request(req).and_then(move |res| {
assert_eq!(res.status(), hyper::StatusCode::OK);
Timeout::new(Duration::from_secs(1), &handle).unwrap()
.from_err()
});
@@ -732,15 +744,18 @@ mod dispatch_impl {
let _ = tx1.send(());
});
let uri = format!("http://{}/a", addr).parse().unwrap();
let res = {
let client = Client::configure()
.connector(DebugConnector::with_http_and_closes(HttpConnector::new(1, &handle), closes_tx))
.build(&handle);
client.get(uri).and_then(move |res| {
assert_eq!(res.status(), hyper::StatusCode::Ok);
res.body().concat2()
let req = Request::builder()
.uri(&*format!("http://{}/a", addr))
.body(Body::empty())
.unwrap();
client.request(req).and_then(move |res| {
assert_eq!(res.status(), hyper::StatusCode::OK);
res.into_parts().1.concat2()
}).and_then(|_| {
Timeout::new(Duration::from_secs(1), &handle).unwrap()
.from_err()
@@ -783,14 +798,17 @@ mod dispatch_impl {
let _ = client_drop_rx.wait();
});
let uri = format!("http://{}/a", addr).parse().unwrap();
let client = Client::configure()
.connector(DebugConnector::with_http_and_closes(HttpConnector::new(1, &handle), closes_tx))
.build(&handle);
let res = client.get(uri).and_then(move |res| {
assert_eq!(res.status(), hyper::StatusCode::Ok);
res.body().concat2()
let req = Request::builder()
.uri(&*format!("http://{}/a", addr))
.body(Body::empty())
.unwrap();
let res = client.request(req).and_then(move |res| {
assert_eq!(res.status(), hyper::StatusCode::OK);
res.into_parts().1.concat2()
});
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
core.run(res.join(rx).map(|r| r.0)).unwrap();
@@ -843,13 +861,16 @@ mod dispatch_impl {
let _ = client_drop_rx.wait();
});
let uri = format!("http://{}/a", addr).parse().unwrap();
let res = {
let client = Client::configure()
.connector(DebugConnector::with_http_and_closes(HttpConnector::new(1, &handle), closes_tx))
.build(&handle);
client.get(uri)
let req = Request::builder()
.uri(&*format!("http://{}/a", addr))
.body(Body::empty())
.unwrap();
client.request(req)
};
//let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
@@ -892,14 +913,17 @@ mod dispatch_impl {
let _ = client_drop_rx.wait();
});
let uri = format!("http://{}/a", addr).parse().unwrap();
let res = {
let client = Client::configure()
.connector(DebugConnector::with_http_and_closes(HttpConnector::new(1, &handle), closes_tx))
.build(&handle);
let req = Request::builder()
.uri(&*format!("http://{}/a", addr))
.body(Body::empty())
.unwrap();
// notably, havent read body yet
client.get(uri)
client.request(req)
};
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
@@ -927,6 +951,7 @@ mod dispatch_impl {
let (closes_tx, closes) = mpsc::channel(10);
let (tx1, rx1) = oneshot::channel();
let (_tx2, rx2) = oneshot::channel::<()>();
thread::spawn(move || {
let mut sock = server.accept().unwrap().0;
@@ -936,17 +961,21 @@ mod dispatch_impl {
sock.read(&mut buf).expect("read 1");
sock.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n").unwrap();
let _ = tx1.send(());
let _ = rx2.wait();
});
let uri = format!("http://{}/a", addr).parse().unwrap();
let client = Client::configure()
.connector(DebugConnector::with_http_and_closes(HttpConnector::new(1, &handle), closes_tx))
.keep_alive(false)
.build(&handle);
let res = client.get(uri).and_then(move |res| {
assert_eq!(res.status(), hyper::StatusCode::Ok);
res.body().concat2()
let req = Request::builder()
.uri(&*format!("http://{}/a", addr))
.body(Body::empty())
.unwrap();
let res = client.request(req).and_then(move |res| {
assert_eq!(res.status(), hyper::StatusCode::OK);
res.into_parts().1.concat2()
});
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
core.run(res.join(rx).map(|r| r.0)).unwrap();
@@ -984,14 +1013,17 @@ mod dispatch_impl {
let _ = tx1.send(());
});
let uri = format!("http://{}/a", addr).parse().unwrap();
let client = Client::configure()
.connector(DebugConnector::with_http_and_closes(HttpConnector::new(1, &handle), closes_tx))
.build(&handle);
let res = client.get(uri).and_then(move |res| {
assert_eq!(res.status(), hyper::StatusCode::Ok);
res.body().concat2()
let req = Request::builder()
.uri(&*format!("http://{}/a", addr))
.body(Body::empty())
.unwrap();
let res = client.request(req).and_then(move |res| {
assert_eq!(res.status(), hyper::StatusCode::OK);
res.into_parts().1.concat2()
});
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
core.run(res.join(rx).map(|r| r.0)).unwrap();
@@ -1039,9 +1071,14 @@ mod dispatch_impl {
let uri = format!("http://{}/a", addr).parse::<hyper::Uri>().unwrap();
let client = Client::new(&handle);
let res = client.get(uri.clone()).and_then(move |res| {
assert_eq!(res.status(), hyper::StatusCode::Ok);
res.body().concat2()
let req = Request::builder()
.uri(uri.clone())
.body(Body::empty())
.unwrap();
let res = client.request(req).and_then(move |res| {
assert_eq!(res.status(), hyper::StatusCode::OK);
res.into_parts().1.concat2()
});
core.run(res).unwrap();
@@ -1052,7 +1089,11 @@ mod dispatch_impl {
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
let rx = rx.and_then(move |_| timeout.map_err(|e| e.into()));
let res = client.get(uri);
let req = Request::builder()
.uri(uri)
.body(Body::empty())
.unwrap();
let res = client.request(req);
// this does trigger an 'event loop gone' error, but before, it would
// panic internally on a `SendError`, which is what we're testing against.
let err = core.run(res.join(rx).map(|r| r.0)).unwrap_err();
@@ -1079,14 +1120,17 @@ mod dispatch_impl {
let _ = tx1.send(());
});
let uri = format!("http://{}/a", addr).parse().unwrap();
let client = Client::configure()
.connector(DebugConnector::with_http_and_closes(HttpConnector::new(1, &handle), closes_tx))
.executor(handle.clone());
let res = client.get(uri).and_then(move |res| {
assert_eq!(res.status(), hyper::StatusCode::Ok);
res.body().concat2()
let req = Request::builder()
.uri(&*format!("http://{}/a", addr))
.body(Body::empty())
.unwrap();
let res = client.request(req).and_then(move |res| {
assert_eq!(res.status(), hyper::StatusCode::OK);
res.into_parts().1.concat2()
});
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
@@ -1111,21 +1155,21 @@ mod dispatch_impl {
// idle connections that the Checkout would have found
let _ = pretty_env_logger::try_init();
let server = TcpListener::bind("127.0.0.1:0").unwrap();
let addr = server.local_addr().unwrap();
let core = Core::new().unwrap();
let handle = core.handle();
let connector = DebugConnector::new(&handle);
let connects = connector.connects.clone();
let uri: hyper::Uri = format!("http://{}/a", addr).parse().unwrap();
let client = Client::configure()
.connector(connector)
.build(&handle);
assert_eq!(connects.load(Ordering::Relaxed), 0);
let _fut = client.get(uri);
let req = Request::builder()
.uri("http://hyper.local/a")
.body(Default::default())
.unwrap();
let _fut = client.request(req);
// internal Connect::connect should have been lazy, and not
// triggered an actual connect yet.
assert_eq!(connects.load(Ordering::Relaxed), 0);
@@ -1169,13 +1213,25 @@ mod dispatch_impl {
assert_eq!(connects.load(Ordering::Relaxed), 0);
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
let res = client.get(format!("http://{}/a", addr).parse().unwrap());
let req = Request::builder()
.uri(&*format!("http://{}/a", addr))
//TODO: remove this header when auto lengths are fixed
.header("content-length", "0")
.body(Body::empty())
.unwrap();
let res = client.request(req);
core.run(res.join(rx).map(|r| r.0)).unwrap();
assert_eq!(connects.load(Ordering::Relaxed), 1);
let rx = rx2.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
let res = client.get(format!("http://{}/b", addr).parse().unwrap());
let req = Request::builder()
.uri(&*format!("http://{}/b", addr))
//TODO: remove this header when auto lengths are fixed
.header("content-length", "0")
.body(Body::empty())
.unwrap();
let res = client.request(req);
core.run(res.join(rx).map(|r| r.0)).unwrap();
assert_eq!(connects.load(Ordering::Relaxed), 1, "second request should still only have 1 connect");
@@ -1222,14 +1278,26 @@ mod dispatch_impl {
assert_eq!(connects.load(Ordering::Relaxed), 0);
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
let req = Request::new(Method::Head, format!("http://{}/a", addr).parse().unwrap());
let req = Request::builder()
.method("HEAD")
.uri(&*format!("http://{}/a", addr))
//TODO: remove this header when auto lengths are fixed
.header("content-length", "0")
.body(Body::empty())
.unwrap();
let res = client.request(req);
core.run(res.join(rx).map(|r| r.0)).unwrap();
assert_eq!(connects.load(Ordering::Relaxed), 1);
let rx = rx2.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
let res = client.get(format!("http://{}/b", addr).parse().unwrap());
let req = Request::builder()
.uri(&*format!("http://{}/b", addr))
//TODO: remove this header when auto lengths are fixed
.header("content-length", "0")
.body(Body::empty())
.unwrap();
let res = client.request(req);
core.run(res.join(rx).map(|r| r.0)).unwrap();
assert_eq!(connects.load(Ordering::Relaxed), 2);
@@ -1323,7 +1391,7 @@ mod conn {
use tokio_core::net::TcpStream;
use tokio_io::{AsyncRead, AsyncWrite};
use hyper::{self, Method, Request};
use hyper::{self, Request};
use hyper::client::conn;
use super::s;
@@ -1360,12 +1428,13 @@ mod conn {
handle.spawn(conn.map(|_| ()).map_err(|e| panic!("conn error: {}", e)));
let uri = "/a".parse().unwrap();
let req = Request::new(Method::Get, uri);
let req = Request::builder()
.uri("/a")
.body(Default::default())
.unwrap();
let res = client.send_request(req).and_then(move |res| {
assert_eq!(res.status(), hyper::StatusCode::Ok);
res.body().concat2()
assert_eq!(res.status(), hyper::StatusCode::OK);
res.into_body().concat2()
});
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
@@ -1405,12 +1474,14 @@ mod conn {
handle.spawn(conn.map(|_| ()).map_err(|e| panic!("conn error: {}", e)));
let uri = "http://hyper.local/a".parse().unwrap();
let req = Request::new(Method::Get, uri);
let req = Request::builder()
.uri("http://hyper.local/a")
.body(Default::default())
.unwrap();
let res = client.send_request(req).and_then(move |res| {
assert_eq!(res.status(), hyper::StatusCode::Ok);
res.body().concat2()
assert_eq!(res.status(), hyper::StatusCode::OK);
res.into_body().concat2()
});
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
@@ -1419,7 +1490,6 @@ mod conn {
core.run(res.join(rx).map(|r| r.0)).unwrap();
}
#[test]
fn pipeline() {
let server = TcpListener::bind("127.0.0.1:0").unwrap();
@@ -1436,6 +1506,7 @@ mod conn {
let mut buf = [0; 4096];
sock.read(&mut buf).expect("read 1");
sock.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n").unwrap();
let _ = tx1.send(());
});
@@ -1445,16 +1516,20 @@ mod conn {
handle.spawn(conn.map(|_| ()).map_err(|e| panic!("conn error: {}", e)));
let uri = "/a".parse().unwrap();
let req = Request::new(Method::Get, uri);
let req = Request::builder()
.uri("/a")
.body(Default::default())
.unwrap();
let res1 = client.send_request(req).and_then(move |res| {
assert_eq!(res.status(), hyper::StatusCode::Ok);
res.body().concat2()
assert_eq!(res.status(), hyper::StatusCode::OK);
res.into_body().concat2()
});
// pipelined request will hit NotReady, and thus should return an Error::Cancel
let uri = "/b".parse().unwrap();
let req = Request::new(Method::Get, uri);
let req = Request::builder()
.uri("/b")
.body(Default::default())
.unwrap();
let res2 = client.send_request(req)
.then(|result| {
let err = result.expect_err("res2");
@@ -1517,12 +1592,14 @@ mod conn {
conn.poll_without_shutdown()
});
let uri = "/a".parse().unwrap();
let req = Request::new(Method::Get, uri);
let req = Request::builder()
.uri("/a")
.body(Default::default())
.unwrap();
let res = client.send_request(req).and_then(move |res| {
assert_eq!(res.status(), hyper::StatusCode::SwitchingProtocols);
assert_eq!(res.headers().get_raw("Upgrade").unwrap(), "foobar");
res.body().concat2()
assert_eq!(res.status(), hyper::StatusCode::SWITCHING_PROTOCOLS);
assert_eq!(res.headers()["Upgrade"], "foobar");
res.into_body().concat2()
});
let rx = rx1.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));
@@ -1595,12 +1672,15 @@ mod conn {
conn.poll_without_shutdown()
});
let uri = format!("http://{}", addr).parse().unwrap();
let req = Request::new(Method::Connect, uri);
let req = Request::builder()
.method("CONNECT")
.uri(addr.to_string())
.body(Default::default())
.unwrap();
let res = client.send_request(req)
.and_then(move |res| {
assert_eq!(res.status(), hyper::StatusCode::Ok);
res.body().concat2()
assert_eq!(res.status(), hyper::StatusCode::OK);
res.into_body().concat2()
})
.map(|body| {
assert_eq!(body.as_ref(), b"");