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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 4 additions & 4 deletions
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));

0 commit comments

Comments
 (0)