Skip to content

Commit 5261c37

Browse files
rename body to recv temporarily
""" We'll eventually want to bikshed the name Recv, but to free up the name Body for #2839, this can be done quickly. """ Resolve #2963
1 parent 49d4d85 commit 5261c37

35 files changed

+253
-253
lines changed

benches/pipeline.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use tokio::sync::oneshot;
1313

1414
use hyper::server::conn::Http;
1515
use hyper::service::service_fn;
16-
use hyper::{Body, Response};
16+
use hyper::{Recv, Response};
1717

1818
const PIPELINED_REQUESTS: usize = 16;
1919

@@ -43,7 +43,7 @@ fn hello_world_16(b: &mut test::Bencher) {
4343
.serve_connection(
4444
stream,
4545
service_fn(|_| async {
46-
Ok::<_, hyper::Error>(Response::new(Body::from("Hello, World!")))
46+
Ok::<_, hyper::Error>(Response::new(Recv::from("Hello, World!")))
4747
}),
4848
)
4949
.await

benches/server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ macro_rules! bench_server {
8787
}};
8888
}
8989

90-
fn body(b: &'static [u8]) -> hyper::Body {
90+
fn body(b: &'static [u8]) -> hyper::Recv {
9191
b.into()
9292
}
9393

examples/client.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![warn(rust_2018_idioms)]
33
use std::env;
44

5-
use hyper::{body::HttpBody as _, Body, Request};
5+
use hyper::{body::HttpBody as _, Recv, Request};
66
use tokio::io::{self, AsyncWriteExt as _};
77
use tokio::net::TcpStream;
88

@@ -51,7 +51,7 @@ async fn fetch_url(url: hyper::Uri) -> Result<()> {
5151
let req = Request::builder()
5252
.uri(url)
5353
.header(hyper::header::HOST, authority.as_str())
54-
.body(Body::empty())?;
54+
.body(Recv::empty())?;
5555

5656
let mut res = sender.send_request(req).await?;
5757

examples/client_json.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![deny(warnings)]
22
#![warn(rust_2018_idioms)]
33

4-
use hyper::Body;
4+
use hyper::Recv;
55
use hyper::{body::Buf, Request};
66
use serde::Deserialize;
77
use tokio::net::TcpStream;
@@ -42,7 +42,7 @@ async fn fetch_json(url: hyper::Uri) -> Result<Vec<User>> {
4242
let req = Request::builder()
4343
.uri(url)
4444
.header(hyper::header::HOST, authority.as_str())
45-
.body(Body::empty())?;
45+
.body(Recv::empty())?;
4646

4747
let res = sender.send_request(req).await?;
4848

examples/echo.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ use std::net::SocketAddr;
55
use hyper::body::HttpBody as _;
66
use hyper::server::conn::Http;
77
use hyper::service::service_fn;
8-
use hyper::{Body, Method, Request, Response, StatusCode};
8+
use hyper::{Method, Recv, Request, Response, StatusCode};
99
use tokio::net::TcpListener;
1010

1111
/// This is our service handler. It receives a Request, routes on its
1212
/// path, and returns a Future of a Response.
13-
async fn echo(req: Request<Body>) -> Result<Response<Body>, hyper::Error> {
13+
async fn echo(req: Request<Recv>) -> Result<Response<Recv>, hyper::Error> {
1414
match (req.method(), req.uri().path()) {
1515
// Serve some instructions at /
16-
(&Method::GET, "/") => Ok(Response::new(Body::from(
16+
(&Method::GET, "/") => Ok(Response::new(Recv::from(
1717
"Try POSTing data to /echo such as: `curl localhost:3000/echo -XPOST -d 'hello world'`",
1818
))),
1919

@@ -43,15 +43,15 @@ async fn echo(req: Request<Body>) -> Result<Response<Body>, hyper::Error> {
4343
// 64kbs of data.
4444
let max = req.body().size_hint().upper().unwrap_or(u64::MAX);
4545
if max > 1024 * 64 {
46-
let mut resp = Response::new(Body::from("Body too big"));
46+
let mut resp = Response::new(Recv::from("Body too big"));
4747
*resp.status_mut() = hyper::StatusCode::PAYLOAD_TOO_LARGE;
4848
return Ok(resp);
4949
}
5050

5151
let whole_body = hyper::body::to_bytes(req.into_body()).await?;
5252

5353
let reversed_body = whole_body.iter().rev().cloned().collect::<Vec<u8>>();
54-
Ok(Response::new(Body::from(reversed_body)))
54+
Ok(Response::new(Recv::from(reversed_body)))
5555
}
5656

5757
// Return the 404 Not Found for other routes.

examples/hello.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use std::net::SocketAddr;
55

66
use hyper::server::conn::Http;
77
use hyper::service::service_fn;
8-
use hyper::{Body, Request, Response};
8+
use hyper::{Recv, Request, Response};
99
use tokio::net::TcpListener;
1010

11-
async fn hello(_: Request<Body>) -> Result<Response<Body>, Infallible> {
12-
Ok(Response::new(Body::from("Hello World!")))
11+
async fn hello(_: Request<Recv>) -> Result<Response<Recv>, Infallible> {
12+
Ok(Response::new(Recv::from("Hello World!")))
1313
}
1414

1515
#[tokio::main]

examples/http_proxy.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use hyper::client::conn::http1::Builder;
66
use hyper::server::conn::Http;
77
use hyper::service::service_fn;
88
use hyper::upgrade::Upgraded;
9-
use hyper::{Body, Method, Request, Response};
9+
use hyper::{Method, Recv, Request, Response};
1010

1111
use tokio::net::{TcpListener, TcpStream};
1212

@@ -41,7 +41,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4141
}
4242
}
4343

44-
async fn proxy(req: Request<Body>) -> Result<Response<Body>, hyper::Error> {
44+
async fn proxy(req: Request<Recv>) -> Result<Response<Recv>, hyper::Error> {
4545
println!("req: {:?}", req);
4646

4747
if Method::CONNECT == req.method() {
@@ -70,10 +70,10 @@ async fn proxy(req: Request<Body>) -> Result<Response<Body>, hyper::Error> {
7070
}
7171
});
7272

73-
Ok(Response::new(Body::empty()))
73+
Ok(Response::new(Recv::empty()))
7474
} else {
7575
eprintln!("CONNECT host is not socket addr: {:?}", req.uri());
76-
let mut resp = Response::new(Body::from("CONNECT must be to a socket address"));
76+
let mut resp = Response::new(Recv::from("CONNECT must be to a socket address"));
7777
*resp.status_mut() = http::StatusCode::BAD_REQUEST;
7878

7979
Ok(resp)

examples/multi_server.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ use std::net::SocketAddr;
66
use futures_util::future::join;
77
use hyper::server::conn::Http;
88
use hyper::service::service_fn;
9-
use hyper::{Body, Request, Response};
9+
use hyper::{Recv, Request, Response};
1010
use tokio::net::TcpListener;
1111

1212
static INDEX1: &[u8] = b"The 1st service!";
1313
static INDEX2: &[u8] = b"The 2nd service!";
1414

15-
async fn index1(_: Request<Body>) -> Result<Response<Body>, hyper::Error> {
16-
Ok(Response::new(Body::from(INDEX1)))
15+
async fn index1(_: Request<Recv>) -> Result<Response<Recv>, hyper::Error> {
16+
Ok(Response::new(Recv::from(INDEX1)))
1717
}
1818

19-
async fn index2(_: Request<Body>) -> Result<Response<Body>, hyper::Error> {
20-
Ok(Response::new(Body::from(INDEX2)))
19+
async fn index2(_: Request<Recv>) -> Result<Response<Recv>, hyper::Error> {
20+
Ok(Response::new(Recv::from(INDEX2)))
2121
}
2222

2323
#[tokio::main]

examples/params.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use hyper::server::conn::Http;
55
use hyper::service::service_fn;
6-
use hyper::{Body, Method, Request, Response, StatusCode};
6+
use hyper::{Method, Recv, Request, Response, StatusCode};
77
use tokio::net::TcpListener;
88

99
use std::collections::HashMap;
@@ -15,7 +15,7 @@ static MISSING: &[u8] = b"Missing field";
1515
static NOTNUMERIC: &[u8] = b"Number field is not numeric";
1616

1717
// Using service_fn, we can turn this function into a `Service`.
18-
async fn param_example(req: Request<Body>) -> Result<Response<Body>, hyper::Error> {
18+
async fn param_example(req: Request<Recv>) -> Result<Response<Recv>, hyper::Error> {
1919
match (req.method(), req.uri().path()) {
2020
(&Method::GET, "/") | (&Method::GET, "/post") => Ok(Response::new(INDEX.into())),
2121
(&Method::POST, "/post") => {
@@ -96,7 +96,7 @@ async fn param_example(req: Request<Body>) -> Result<Response<Body>, hyper::Erro
9696
}
9797
_ => Ok(Response::builder()
9898
.status(StatusCode::NOT_FOUND)
99-
.body(Body::empty())
99+
.body(Recv::empty())
100100
.unwrap()),
101101
}
102102
}

examples/send_file.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use hyper::server::conn::Http;
66
use tokio::net::TcpListener;
77

88
use hyper::service::service_fn;
9-
use hyper::{Body, Method, Request, Response, Result, StatusCode};
9+
use hyper::{Method, Recv, Request, Response, Result, StatusCode};
1010

1111
static INDEX: &str = "examples/send_file_index.html";
1212
static NOTFOUND: &[u8] = b"Not Found";
@@ -34,7 +34,7 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
3434
}
3535
}
3636

37-
async fn response_examples(req: Request<Body>) -> Result<Response<Body>> {
37+
async fn response_examples(req: Request<Recv>) -> Result<Response<Recv>> {
3838
match (req.method(), req.uri().path()) {
3939
(&Method::GET, "/") | (&Method::GET, "/index.html") => simple_file_send(INDEX).await,
4040
(&Method::GET, "/no_file.html") => {
@@ -46,14 +46,14 @@ async fn response_examples(req: Request<Body>) -> Result<Response<Body>> {
4646
}
4747

4848
/// HTTP status code 404
49-
fn not_found() -> Response<Body> {
49+
fn not_found() -> Response<Recv> {
5050
Response::builder()
5151
.status(StatusCode::NOT_FOUND)
5252
.body(NOTFOUND.into())
5353
.unwrap()
5454
}
5555

56-
async fn simple_file_send(filename: &str) -> Result<Response<Body>> {
56+
async fn simple_file_send(filename: &str) -> Result<Response<Recv>> {
5757
if let Ok(contents) = tokio::fs::read(filename).await {
5858
let body = contents.into();
5959
return Ok(Response::new(body));

examples/service_struct_impl.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use hyper::server::conn::Http;
22
use hyper::service::Service;
3-
use hyper::{Body, Request, Response};
3+
use hyper::{Recv, Request, Response};
44
use tokio::net::TcpListener;
55

66
use std::future::Future;
@@ -35,18 +35,18 @@ struct Svc {
3535
counter: Counter,
3636
}
3737

38-
impl Service<Request<Body>> for Svc {
39-
type Response = Response<Body>;
38+
impl Service<Request<Recv>> for Svc {
39+
type Response = Response<Recv>;
4040
type Error = hyper::Error;
4141
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
4242

4343
fn poll_ready(&mut self, _: &mut Context) -> Poll<Result<(), Self::Error>> {
4444
Poll::Ready(Ok(()))
4545
}
4646

47-
fn call(&mut self, req: Request<Body>) -> Self::Future {
48-
fn mk_response(s: String) -> Result<Response<Body>, hyper::Error> {
49-
Ok(Response::builder().body(Body::from(s)).unwrap())
47+
fn call(&mut self, req: Request<Recv>) -> Self::Future {
48+
fn mk_response(s: String) -> Result<Response<Recv>, hyper::Error> {
49+
Ok(Response::builder().body(Recv::from(s)).unwrap())
5050
}
5151

5252
let res = match req.uri().path() {

examples/state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::sync::{
77
};
88

99
use hyper::{server::conn::Http, service::service_fn};
10-
use hyper::{Body, Error, Response};
10+
use hyper::{Error, Recv, Response};
1111
use tokio::net::TcpListener;
1212

1313
#[tokio::main]
@@ -36,7 +36,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3636
// Get the current count, and also increment by 1, in a single
3737
// atomic operation.
3838
let count = counter.fetch_add(1, Ordering::AcqRel);
39-
async move { Ok::<_, Error>(Response::new(Body::from(format!("Request #{}", count)))) }
39+
async move { Ok::<_, Error>(Response::new(Recv::from(format!("Request #{}", count)))) }
4040
});
4141

4242
if let Err(err) = Http::new().serve_connection(stream, service).await {

examples/tower_server.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,34 @@ use std::task::{Context, Poll};
66
use futures_util::future;
77
use hyper::server::conn::Http;
88
use hyper::service::Service;
9-
use hyper::{Body, Request, Response};
9+
use hyper::{Recv, Request, Response};
1010
use tokio::net::TcpListener;
1111

1212
const ROOT: &str = "/";
1313

1414
#[derive(Debug)]
1515
pub struct Svc;
1616

17-
impl Service<Request<Body>> for Svc {
18-
type Response = Response<Body>;
17+
impl Service<Request<Recv>> for Svc {
18+
type Response = Response<Recv>;
1919
type Error = hyper::Error;
2020
type Future = future::Ready<Result<Self::Response, Self::Error>>;
2121

2222
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
2323
Ok(()).into()
2424
}
2525

26-
fn call(&mut self, req: Request<Body>) -> Self::Future {
26+
fn call(&mut self, req: Request<Recv>) -> Self::Future {
2727
let rsp = Response::builder();
2828

2929
let uri = req.uri();
3030
if uri.path() != ROOT {
31-
let body = Body::from(Vec::new());
31+
let body = Recv::from(Vec::new());
3232
let rsp = rsp.status(404).body(body).unwrap();
3333
return future::ok(rsp);
3434
}
3535

36-
let body = Body::from(Vec::from(&b"heyo!"[..]));
36+
let body = Recv::from(Vec::from(&b"heyo!"[..]));
3737
let rsp = rsp.status(200).body(body).unwrap();
3838
future::ok(rsp)
3939
}

examples/upgrades.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use tokio::sync::watch;
1111
use hyper::header::{HeaderValue, UPGRADE};
1212
use hyper::service::service_fn;
1313
use hyper::upgrade::Upgraded;
14-
use hyper::{Body, Request, Response, StatusCode};
14+
use hyper::{Recv, Request, Response, StatusCode};
1515
use std::net::SocketAddr;
1616

1717
// A simple type alias so as to DRY.
@@ -36,8 +36,8 @@ async fn server_upgraded_io(mut upgraded: Upgraded) -> Result<()> {
3636
}
3737

3838
/// Our server HTTP handler to initiate HTTP upgrades.
39-
async fn server_upgrade(mut req: Request<Body>) -> Result<Response<Body>> {
40-
let mut res = Response::new(Body::empty());
39+
async fn server_upgrade(mut req: Request<Recv>) -> Result<Response<Recv>> {
40+
let mut res = Response::new(Recv::empty());
4141

4242
// Send a 400 to any request that doesn't have
4343
// an `Upgrade` header.
@@ -91,7 +91,7 @@ async fn client_upgrade_request(addr: SocketAddr) -> Result<()> {
9191
let req = Request::builder()
9292
.uri(format!("http://{}/", addr))
9393
.header(UPGRADE, "foobar")
94-
.body(Body::empty())
94+
.body(Recv::empty())
9595
.unwrap();
9696

9797
let stream = TcpStream::connect(addr).await?;

0 commit comments

Comments
 (0)