diff --git a/Cargo.lock b/Cargo.lock index cffc17f14..8df72ffdb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -499,6 +499,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", + "socket2 0.4.10", "tokio", "tower-service", "tracing", @@ -537,7 +538,7 @@ dependencies = [ "http-body 1.0.0", "hyper 1.1.0", "pin-project-lite", - "socket2", + "socket2 0.5.5", "tokio", "tracing", ] @@ -1085,6 +1086,16 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +[[package]] +name = "socket2" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "socket2" version = "0.5.5" @@ -1202,7 +1213,7 @@ dependencies = [ "mio", "num_cpus", "pin-project-lite", - "socket2", + "socket2 0.5.5", "tokio-macros", "windows-sys 0.48.0", ] diff --git a/Cargo.toml b/Cargo.toml index 763477818..34b05580f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,5 +33,6 @@ seq-macro = "0.3" [dev-dependencies] specit = {version = "0.4.0", features = ["tokio"] } -hyper = { version = "0.14", features = [ "client" ] } +# TODO: use hyper 1 in tests +hyper_0_14 = { package = "hyper", version = "0.14", features = [ "client", "stream", "tcp", "http1" ] } regex = "1.9" diff --git a/tests/piping_server.rs b/tests/piping_server.rs index 800913f57..c58021ce4 100644 --- a/tests/piping_server.rs +++ b/tests/piping_server.rs @@ -1,11 +1,9 @@ use futures::channel::oneshot; -use hyper::service::{make_service_fn, service_fn}; -use hyper::Client; -use hyper::Server; +use hyper_0_14::Client; use regex::Regex; use specit::tokio_it as it; -use std::convert::Infallible; +use futures::FutureExt; use piping_server::piping_server::PipingServer; use std::net::SocketAddr; use std::time; @@ -13,15 +11,15 @@ use std::time; type BoxError = Box; fn get_header_value<'a>( - headers: &'a hyper::header::HeaderMap, + headers: &'a hyper_0_14::header::HeaderMap, key: &'static str, ) -> Option<&'a str> { headers.get(key).map(|v| v.to_str().unwrap()) } // Read all bytes from body -async fn read_all_body(mut body: hyper::body::Body) -> Vec { - use futures::stream::StreamExt; +async fn read_all_body(mut body: hyper_0_14::body::Body) -> Vec { + use futures::stream::StreamExt as _; let mut all_bytes: Vec = Vec::new(); loop { @@ -45,27 +43,37 @@ async fn serve() -> Serve { let piping_server = PipingServer::new(); let (addr_tx, addr_rx) = oneshot::channel::(); - let (shutdown_tx, shutdown_rx) = oneshot::channel::<()>(); + let (shutdown_tx, mut shutdown_rx) = oneshot::channel::<()>(); let (shutdown_finished_tx, shutdown_finished_rx) = oneshot::channel::<()>(); tokio::spawn(async move { - let http_svc = make_service_fn(|_| { - let piping_server = piping_server.clone(); - futures::future::ok::<_, Infallible>(service_fn(move |req| { - piping_server.handler(false, req) - })) - }); - let http_server = Server::bind(&([127, 0, 0, 1], 0).into()).serve(http_svc); + let piping_server = piping_server.clone(); + let piping_server_service = + hyper::service::service_fn(move |req| piping_server.clone().handle(false, req)); + let tcp_listener = tokio::net::TcpListener::bind::<(_, u16)>(("127.0.0.1", 0).into()) + .await + .unwrap(); addr_tx - .send(http_server.local_addr()) + .send(tcp_listener.local_addr().unwrap()) .expect("server address send failed"); - http_server - .with_graceful_shutdown(async { - let _ = shutdown_rx.await; - }) - .await - .expect("failed to shutdown in server-side"); + loop { + let accept_fut = tcp_listener.accept().fuse(); + futures::pin_mut!(accept_fut); + let (stream, _) = futures::select! { + accepted = accept_fut => accepted.unwrap(), + _ = shutdown_rx => break, + }; + let piping_server_service = piping_server_service.clone(); + tokio::task::spawn(async move { + hyper_util::server::conn::auto::Builder::new( + hyper_util::rt::tokio::TokioExecutor::new(), + ) + .serve_connection(hyper_util::rt::TokioIo::new(stream), piping_server_service) + .await + .unwrap() + }); + } shutdown_finished_tx.send(()).unwrap(); }); @@ -92,12 +100,12 @@ impl Serve { async fn f() -> Result<(), BoxError> { let serve: Serve = serve().await; - let uri = format!("http://{}", serve.addr).parse::()?; + let uri = format!("http://{}", serve.addr).parse::()?; - let get_req = hyper::Request::builder() - .method(hyper::Method::GET) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::GET) .uri(uri.clone()) - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let client = Client::new(); let res = client.request(get_req).await?; @@ -125,12 +133,13 @@ async fn f() -> Result<(), BoxError> { async fn f() -> Result<(), BoxError> { let serve: Serve = serve().await; - let uri = format!("http://{}/noscript?path=mypath", serve.addr).parse::()?; + let uri = + format!("http://{}/noscript?path=mypath", serve.addr).parse::()?; - let get_req = hyper::Request::builder() - .method(hyper::Method::GET) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::GET) .uri(uri.clone()) - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let client = Client::new(); let res = client.request(get_req).await?; @@ -163,12 +172,12 @@ async fn f() -> Result<(), BoxError> { async fn f() -> Result<(), BoxError> { let serve: Serve = serve().await; - let uri = format!("http://{}/version", serve.addr).parse::()?; + let uri = format!("http://{}/version", serve.addr).parse::()?; - let get_req = hyper::Request::builder() - .method(hyper::Method::GET) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::GET) .uri(uri.clone()) - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let client = Client::new(); let res = client.request(get_req).await?; @@ -197,12 +206,12 @@ async fn f() -> Result<(), BoxError> { async fn f() -> Result<(), BoxError> { let serve: Serve = serve().await; - let uri = format!("http://{}/help", serve.addr).parse::()?; + let uri = format!("http://{}/help", serve.addr).parse::()?; - let get_req = hyper::Request::builder() - .method(hyper::Method::GET) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::GET) .uri(uri.clone()) - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let client = Client::new(); let res = client.request(get_req).await?; @@ -225,12 +234,12 @@ async fn f() -> Result<(), BoxError> { async fn f() -> Result<(), BoxError> { let serve: Serve = serve().await; - let uri = format!("http://{}/favicon.ico", serve.addr).parse::()?; + let uri = format!("http://{}/favicon.ico", serve.addr).parse::()?; - let get_req = hyper::Request::builder() - .method(hyper::Method::GET) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::GET) .uri(uri.clone()) - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let client = Client::new(); let res = client.request(get_req).await?; @@ -240,8 +249,8 @@ async fn f() -> Result<(), BoxError> { let body_len: usize = read_all_body(body).await.len(); assert_eq!(body_len, 0); - let status: http::StatusCode = parts.status; - assert_eq!(status, http::StatusCode::NO_CONTENT); + let status: hyper_0_14::http::StatusCode = parts.status; + assert_eq!(status, hyper_0_14::http::StatusCode::NO_CONTENT); serve.shutdown().await?; Ok(()) @@ -251,12 +260,12 @@ async fn f() -> Result<(), BoxError> { async fn f() -> Result<(), BoxError> { let serve: Serve = serve().await; - let uri = format!("http://{}/robots.txt", serve.addr).parse::()?; + let uri = format!("http://{}/robots.txt", serve.addr).parse::()?; - let get_req = hyper::Request::builder() - .method(hyper::Method::GET) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::GET) .uri(uri.clone()) - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let client = Client::new(); let res = client.request(get_req).await?; @@ -266,7 +275,7 @@ async fn f() -> Result<(), BoxError> { let body_len: usize = read_all_body(body).await.len(); assert_eq!(body_len, 0); - assert_eq!(parts.status, http::StatusCode::NOT_FOUND); + assert_eq!(parts.status, hyper_0_14::http::StatusCode::NOT_FOUND); serve.shutdown().await?; Ok(()) @@ -278,16 +287,17 @@ async fn f() -> Result<(), BoxError> { let client = Client::new(); for reserved_path in piping_server::piping_server::reserved_paths::VALUES { - let uri = format!("http://{}{}", serve.addr, reserved_path).parse::()?; + let uri = + format!("http://{}{}", serve.addr, reserved_path).parse::()?; - let get_req = hyper::Request::builder() - .method(hyper::Method::POST) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::POST) .uri(uri.clone()) - .body(hyper::Body::from("this is a content"))?; + .body(hyper_0_14::Body::from("this is a content"))?; let get_res = client.request(get_req).await?; let (get_parts, _) = get_res.into_parts(); - assert_eq!(get_parts.status, http::StatusCode::BAD_REQUEST); + assert_eq!(get_parts.status, hyper_0_14::http::StatusCode::BAD_REQUEST); assert_eq!( get_header_value(&get_parts.headers, "access-control-allow-origin"), Some("*") @@ -302,27 +312,30 @@ async fn f() -> Result<(), BoxError> { async fn f() -> Result<(), BoxError> { let serve: Serve = serve().await; - fn normalize_headers(headers: &mut http::header::HeaderMap) { + fn normalize_headers( + headers: &mut hyper_0_14::http::header::HeaderMap, + ) { headers.remove("date"); headers.remove("content-security-policy"); } let client = Client::new(); for reserved_path in piping_server::piping_server::reserved_paths::VALUES { - let uri = format!("http://{}{}", serve.addr, reserved_path).parse::()?; + let uri = + format!("http://{}{}", serve.addr, reserved_path).parse::()?; - let get_req = hyper::Request::builder() - .method(hyper::Method::GET) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::GET) .uri(uri.clone()) - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let get_res = client.request(get_req).await?; let (mut get_parts, _) = get_res.into_parts(); normalize_headers(&mut get_parts.headers); - let head_req = hyper::Request::builder() - .method(hyper::Method::HEAD) + let head_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::HEAD) .uri(uri.clone()) - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let head_res = client.request(head_req).await?; let (mut head_parts, _) = head_res.into_parts(); normalize_headers(&mut head_parts.headers); @@ -339,18 +352,18 @@ async fn f() -> Result<(), BoxError> { async fn f() -> Result<(), BoxError> { let serve: Serve = serve().await; - let uri = format!("http://{}/mypath", serve.addr).parse::()?; + let uri = format!("http://{}/mypath", serve.addr).parse::()?; - let get_req = hyper::Request::builder() - .method(hyper::Method::OPTIONS) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::OPTIONS) .uri(uri.clone()) - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let client = Client::new(); let res = client.request(get_req).await?; let (parts, _body) = res.into_parts(); - assert_eq!(parts.status, http::StatusCode::OK); + assert_eq!(parts.status, hyper_0_14::http::StatusCode::OK); assert_eq!( get_header_value(&parts.headers, "access-control-allow-origin"), @@ -385,19 +398,19 @@ async fn f() -> Result<(), BoxError> { async fn f() -> Result<(), BoxError> { let serve: Serve = serve().await; - let uri = format!("http://{}/mypath", serve.addr).parse::()?; + let uri = format!("http://{}/mypath", serve.addr).parse::()?; - let get_req = hyper::Request::builder() - .method(hyper::Method::OPTIONS) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::OPTIONS) .uri(uri.clone()) .header("Access-Control-Request-Private-Network", "true") - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let client = Client::new(); let res = client.request(get_req).await?; let (parts, _body) = res.into_parts(); - assert_eq!(parts.status, http::StatusCode::OK); + assert_eq!(parts.status, hyper_0_14::http::StatusCode::OK); assert_eq!( get_header_value(&parts.headers, "access-control-allow-origin"), @@ -430,19 +443,19 @@ async fn f() -> Result<(), BoxError> { async fn f() -> Result<(), BoxError> { let serve: Serve = serve().await; - let uri = format!("http://{}/mysw.js", serve.addr).parse::()?; + let uri = format!("http://{}/mysw.js", serve.addr).parse::()?; - let get_req = hyper::Request::builder() - .method(hyper::Method::GET) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::GET) .uri(uri.clone()) .header("service-worker", "script") - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let client = Client::new(); let res = client.request(get_req).await?; let (parts, _body) = res.into_parts(); - assert_eq!(parts.status, http::StatusCode::BAD_REQUEST); + assert_eq!(parts.status, hyper_0_14::http::StatusCode::BAD_REQUEST); assert_eq!( get_header_value(&parts.headers, "content-type"), Some("text/plain") @@ -460,19 +473,19 @@ async fn f() -> Result<(), BoxError> { async fn f() -> Result<(), BoxError> { let serve: Serve = serve().await; - let uri = format!("http://{}/mypath", serve.addr).parse::()?; + let uri = format!("http://{}/mypath", serve.addr).parse::()?; - for method in [hyper::Method::POST, hyper::Method::PUT] { - let get_req = hyper::Request::builder() + for method in [hyper_0_14::Method::POST, hyper_0_14::Method::PUT] { + let get_req = hyper_0_14::Request::builder() .method(method) .uri(uri.clone()) .header("Content-Range", "bytes 2-6/100") - .body(hyper::Body::from("hello"))?; + .body(hyper_0_14::Body::from("hello"))?; let client = Client::new(); let res = client.request(get_req).await?; let (parts, _body) = res.into_parts(); - assert_eq!(parts.status, http::StatusCode::BAD_REQUEST); + assert_eq!(parts.status, hyper_0_14::http::StatusCode::BAD_REQUEST); assert_eq!( get_header_value(&parts.headers, "content-type"), Some("text/plain") @@ -491,19 +504,19 @@ async fn f() -> Result<(), BoxError> { async fn f() -> Result<(), BoxError> { let serve: Serve = serve().await; - let uri = format!("http://{}/mypath", serve.addr).parse::()?; + let uri = format!("http://{}/mypath", serve.addr).parse::()?; let send_body_str = "this is a content"; - let send_req = hyper::Request::builder() - .method(hyper::Method::POST) + let send_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::POST) .header("Content-Type", "text/plain") .uri(uri.clone()) - .body(hyper::Body::from(send_body_str))?; + .body(hyper_0_14::Body::from(send_body_str))?; let client = Client::new(); let send_res = client.request(send_req).await?; let (send_res_parts, _send_res_body) = send_res.into_parts(); - assert_eq!(send_res_parts.status, http::StatusCode::OK); + assert_eq!(send_res_parts.status, hyper_0_14::http::StatusCode::OK); assert_eq!( get_header_value(&send_res_parts.headers, "content-type"), Some("text/plain") @@ -513,10 +526,10 @@ async fn f() -> Result<(), BoxError> { Some("*") ); - let get_req = hyper::Request::builder() - .method(hyper::Method::GET) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::GET) .uri(uri.clone()) - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let client = Client::new(); let (parts, body) = client.request(get_req).await?.into_parts(); @@ -558,15 +571,15 @@ async fn f() -> Result<(), BoxError> { async fn f() -> Result<(), BoxError> { let serve: Serve = serve().await; - let uri = format!("http://{}/mypath", serve.addr).parse::()?; + let uri = format!("http://{}/mypath", serve.addr).parse::()?; let get_res_join_handle = tokio::spawn({ let uri = uri.clone(); async { - let get_req = hyper::Request::builder() - .method(hyper::Method::GET) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::GET) .uri(uri) - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let client = Client::new(); let get_res = client.request(get_req).await?; Ok::<_, BoxError>(get_res) @@ -575,16 +588,16 @@ async fn f() -> Result<(), BoxError> { tokio::time::sleep(time::Duration::from_millis(100)).await; let send_body_str = "this is a content"; - let send_req = hyper::Request::builder() - .method(hyper::Method::POST) + let send_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::POST) .header("Content-Type", "text/plain") .uri(uri.clone()) - .body(hyper::Body::from(send_body_str))?; + .body(hyper_0_14::Body::from(send_body_str))?; let client = Client::new(); let send_res = client.request(send_req).await?; let (send_res_parts, _send_res_body) = send_res.into_parts(); - assert_eq!(send_res_parts.status, http::StatusCode::OK); + assert_eq!(send_res_parts.status, hyper_0_14::http::StatusCode::OK); assert_eq!( get_header_value(&send_res_parts.headers, "content-type"), Some("text/plain") @@ -632,20 +645,20 @@ async fn f() -> Result<(), BoxError> { async fn f() -> Result<(), BoxError> { let serve: Serve = serve().await; - let uri = format!("http://{}/mypath", serve.addr).parse::()?; + let uri = format!("http://{}/mypath", serve.addr).parse::()?; { let send_body_str = "this is a content"; - let send_req = hyper::Request::builder() - .method(hyper::Method::POST) + let send_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::POST) .header("Content-Type", "text/plain") .uri(uri.clone()) - .body(hyper::Body::from(send_body_str))?; + .body(hyper_0_14::Body::from(send_body_str))?; let client = Client::new(); let send_res = client.request(send_req).await?; let (send_res_parts, _send_res_body) = send_res.into_parts(); - assert_eq!(send_res_parts.status, http::StatusCode::OK); + assert_eq!(send_res_parts.status, hyper_0_14::http::StatusCode::OK); assert_eq!( get_header_value(&send_res_parts.headers, "content-type"), Some("text/plain") @@ -658,16 +671,19 @@ async fn f() -> Result<(), BoxError> { { let send_body_str = "this is a content"; - let send_req = hyper::Request::builder() - .method(hyper::Method::POST) + let send_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::POST) .header("Content-Type", "text/plain") .uri(uri.clone()) - .body(hyper::Body::from(send_body_str))?; + .body(hyper_0_14::Body::from(send_body_str))?; let client = Client::new(); let send_res = client.request(send_req).await?; let (send_res_parts, _send_res_body) = send_res.into_parts(); - assert_eq!(send_res_parts.status, http::StatusCode::BAD_REQUEST); + assert_eq!( + send_res_parts.status, + hyper_0_14::http::StatusCode::BAD_REQUEST + ); assert_eq!( get_header_value(&send_res_parts.headers, "content-type"), Some("text/plain") @@ -686,12 +702,12 @@ async fn f() -> Result<(), BoxError> { async fn f() -> Result<(), BoxError> { let serve: Serve = serve().await; - let uri = format!("http://{}/mypath", serve.addr).parse::()?; + let uri = format!("http://{}/mypath", serve.addr).parse::()?; - let get_req = hyper::Request::builder() - .method(hyper::Method::GET) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::GET) .uri(uri.clone()) - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let first_get_res_parts_join_handle = tokio::spawn(async { let client = Client::new(); @@ -702,15 +718,18 @@ async fn f() -> Result<(), BoxError> { tokio::time::sleep(time::Duration::from_millis(500)).await; { - let get_req = hyper::Request::builder() - .method(hyper::Method::GET) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::GET) .uri(uri.clone()) - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let client = Client::new(); let get_res = client.request(get_req).await?; let (get_res_parts, _get_res_body) = get_res.into_parts(); - assert_eq!(get_res_parts.status, http::StatusCode::BAD_REQUEST); + assert_eq!( + get_res_parts.status, + hyper_0_14::http::StatusCode::BAD_REQUEST + ); assert_eq!( get_header_value(&get_res_parts.headers, "content-type"), Some("text/plain") @@ -723,18 +742,18 @@ async fn f() -> Result<(), BoxError> { { let send_body_str = "this is a content"; - let send_req = hyper::Request::builder() - .method(hyper::Method::POST) + let send_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::POST) .header("Content-Type", "text/plain") .uri(uri.clone()) - .body(hyper::Body::from(send_body_str))?; + .body(hyper_0_14::Body::from(send_body_str))?; let client = Client::new(); client.request(send_req).await?; } let first_get_res_parts = first_get_res_parts_join_handle.await??; - assert_eq!(first_get_res_parts.status, http::StatusCode::OK); + assert_eq!(first_get_res_parts.status, hyper_0_14::http::StatusCode::OK); assert_eq!( get_header_value(&first_get_res_parts.headers, "content-type"), Some("text/plain") @@ -754,16 +773,19 @@ async fn f() -> Result<(), BoxError> { { let send_body_str = "this is a content"; - let send_req = hyper::Request::builder() - .method(hyper::Method::POST) + let send_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::POST) .header("Content-Type", "text/plain") .uri(format!("http://{}/mypath?n=abc", serve.addr)) - .body(hyper::Body::from(send_body_str))?; + .body(hyper_0_14::Body::from(send_body_str))?; let client = Client::new(); let send_res = client.request(send_req).await?; let (send_res_parts, _send_res_body) = send_res.into_parts(); - assert_eq!(send_res_parts.status, http::StatusCode::BAD_REQUEST); + assert_eq!( + send_res_parts.status, + hyper_0_14::http::StatusCode::BAD_REQUEST + ); assert_eq!( get_header_value(&send_res_parts.headers, "content-type"), Some("text/plain") @@ -775,15 +797,18 @@ async fn f() -> Result<(), BoxError> { } { - let get_req = hyper::Request::builder() - .method(hyper::Method::GET) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::GET) .uri(format!("http://{}/mypath?n=abc", serve.addr)) - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let client = Client::new(); let get_res = client.request(get_req).await?; let (get_res_parts, _get_res_body) = get_res.into_parts(); - assert_eq!(get_res_parts.status, http::StatusCode::BAD_REQUEST); + assert_eq!( + get_res_parts.status, + hyper_0_14::http::StatusCode::BAD_REQUEST + ); assert_eq!( get_header_value(&get_res_parts.headers, "content-type"), Some("text/plain") @@ -804,16 +829,19 @@ async fn f() -> Result<(), BoxError> { { let send_body_str = "this is a content"; - let send_req = hyper::Request::builder() - .method(hyper::Method::POST) + let send_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::POST) .header("Content-Type", "text/plain") .uri(format!("http://{}/mypath?n=0", serve.addr)) - .body(hyper::Body::from(send_body_str))?; + .body(hyper_0_14::Body::from(send_body_str))?; let client = Client::new(); let send_res = client.request(send_req).await?; let (send_res_parts, _send_res_body) = send_res.into_parts(); - assert_eq!(send_res_parts.status, http::StatusCode::BAD_REQUEST); + assert_eq!( + send_res_parts.status, + hyper_0_14::http::StatusCode::BAD_REQUEST + ); assert_eq!( get_header_value(&send_res_parts.headers, "content-type"), Some("text/plain") @@ -825,15 +853,18 @@ async fn f() -> Result<(), BoxError> { } { - let get_req = hyper::Request::builder() - .method(hyper::Method::GET) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::GET) .uri(format!("http://{}/mypath?n=0", serve.addr)) - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let client = Client::new(); let get_res = client.request(get_req).await?; let (get_res_parts, _get_res_body) = get_res.into_parts(); - assert_eq!(get_res_parts.status, http::StatusCode::BAD_REQUEST); + assert_eq!( + get_res_parts.status, + hyper_0_14::http::StatusCode::BAD_REQUEST + ); assert_eq!( get_header_value(&get_res_parts.headers, "content-type"), Some("text/plain") @@ -854,16 +885,19 @@ async fn f() -> Result<(), BoxError> { { let send_body_str = "this is a content"; - let send_req = hyper::Request::builder() - .method(hyper::Method::POST) + let send_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::POST) .header("Content-Type", "text/plain") .uri(format!("http://{}/mypath?n=2", serve.addr)) - .body(hyper::Body::from(send_body_str))?; + .body(hyper_0_14::Body::from(send_body_str))?; let client = Client::new(); let send_res = client.request(send_req).await?; let (send_res_parts, _send_res_body) = send_res.into_parts(); - assert_eq!(send_res_parts.status, http::StatusCode::BAD_REQUEST); + assert_eq!( + send_res_parts.status, + hyper_0_14::http::StatusCode::BAD_REQUEST + ); assert_eq!( get_header_value(&send_res_parts.headers, "content-type"), Some("text/plain") @@ -875,15 +909,18 @@ async fn f() -> Result<(), BoxError> { } { - let get_req = hyper::Request::builder() - .method(hyper::Method::GET) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::GET) .uri(format!("http://{}/mypath?n=2", serve.addr)) - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let client = Client::new(); let get_res = client.request(get_req).await?; let (get_res_parts, _get_res_body) = get_res.into_parts(); - assert_eq!(get_res_parts.status, http::StatusCode::BAD_REQUEST); + assert_eq!( + get_res_parts.status, + hyper_0_14::http::StatusCode::BAD_REQUEST + ); assert_eq!( get_header_value(&get_res_parts.headers, "content-type"), Some("text/plain") @@ -902,25 +939,25 @@ async fn f() -> Result<(), BoxError> { async fn f() -> Result<(), BoxError> { let serve: Serve = serve().await; - let uri = format!("http://{}/mypath", serve.addr).parse::()?; + let uri = format!("http://{}/mypath", serve.addr).parse::()?; let send_body_str = "this is a content"; - let send_req = hyper::Request::builder() - .method(hyper::Method::POST) + let send_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::POST) .header("Content-Type", "text/plain") .header("X-Piping", "mymetadata") .uri(uri.clone()) - .body(hyper::Body::from(send_body_str))?; + .body(hyper_0_14::Body::from(send_body_str))?; let client = Client::new(); let send_res = client.request(send_req).await?; let (send_res_parts, _send_res_body) = send_res.into_parts(); - assert_eq!(send_res_parts.status, http::StatusCode::OK); + assert_eq!(send_res_parts.status, hyper_0_14::http::StatusCode::OK); - let get_req = hyper::Request::builder() - .method(hyper::Method::GET) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::GET) .uri(uri.clone()) - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let client = Client::new(); let (parts, body) = client.request(get_req).await?.into_parts(); @@ -966,27 +1003,27 @@ async fn f() -> Result<(), BoxError> { async fn f() -> Result<(), BoxError> { let serve: Serve = serve().await; - let uri = format!("http://{}/mypath", serve.addr).parse::()?; + let uri = format!("http://{}/mypath", serve.addr).parse::()?; let send_body_str = "this is a content"; - let send_req = hyper::Request::builder() - .method(hyper::Method::POST) + let send_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::POST) .header("Content-Type", "text/plain") .header("X-Piping", "mymetadata1") .header("X-Piping", "mymetadata2") .header("X-Piping", "mymetadata3") .uri(uri.clone()) - .body(hyper::Body::from(send_body_str))?; + .body(hyper_0_14::Body::from(send_body_str))?; let client = Client::new(); let send_res = client.request(send_req).await?; let (send_res_parts, _send_res_body) = send_res.into_parts(); - assert_eq!(send_res_parts.status, http::StatusCode::OK); + assert_eq!(send_res_parts.status, hyper_0_14::http::StatusCode::OK); - let get_req = hyper::Request::builder() - .method(hyper::Method::GET) + let get_req = hyper_0_14::Request::builder() + .method(hyper_0_14::Method::GET) .uri(uri.clone()) - .body(hyper::Body::empty())?; + .body(hyper_0_14::Body::empty())?; let client = Client::new(); let (parts, body) = client.request(get_req).await?.into_parts();