Skip to content

Commit 7a41da5

Browse files
refactor(body): rename Body to Recv temporarily (hyperium#2966)
""" We'll eventually want to bikshed the name Recv, but to free up the name Body for hyperium#2839, this can be done quickly. """ Closes hyperium#2963
1 parent 9e8fc8f commit 7a41da5

29 files changed

+156
-156
lines changed

examples/echo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use http_body_util::{combinators::BoxBody, BodyExt, Empty, Full};
77
use hyper::body::HttpBody as _;
88
use hyper::server::conn::Http;
99
use hyper::service::service_fn;
10-
use hyper::{Body, Method, Request, Response, StatusCode};
10+
use hyper::{Method, Recv, Request, Response, StatusCode};
1111
use tokio::net::TcpListener;
1212

1313
/// This is our service handler. It receives a Request, routes on its
1414
/// path, and returns a Future of a Response.
15-
async fn echo(req: Request<Body>) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
15+
async fn echo(req: Request<Recv>) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
1616
match (req.method(), req.uri().path()) {
1717
// Serve some instructions at /
1818
(&Method::GET, "/") => Ok(Response::new(full(

examples/hello.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use bytes::Bytes;
77
use http_body_util::Full;
88
use hyper::server::conn::Http;
99
use hyper::service::service_fn;
10-
use hyper::{Body, Request, Response};
10+
use hyper::{Recv, Request, Response};
1111
use tokio::net::TcpListener;
1212

13-
async fn hello(_: Request<Body>) -> Result<Response<Full<Bytes>>, Infallible> {
13+
async fn hello(_: Request<Recv>) -> Result<Response<Full<Bytes>>, Infallible> {
1414
Ok(Response::new(Full::new(Bytes::from("Hello World!"))))
1515
}
1616

examples/http_proxy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use hyper::client::conn::Builder;
88
use hyper::server::conn::Http;
99
use hyper::service::service_fn;
1010
use hyper::upgrade::Upgraded;
11-
use hyper::{Body, Method, Request, Response};
11+
use hyper::{Method, Recv, Request, Response};
1212

1313
use tokio::net::{TcpListener, TcpStream};
1414

@@ -43,7 +43,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4343
}
4444
}
4545

46-
async fn proxy(req: Request<Body>) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
46+
async fn proxy(req: Request<Recv>) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
4747
println!("req: {:?}", req);
4848

4949
if Method::CONNECT == req.method() {

examples/multi_server.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ use futures_util::future::join;
88
use http_body_util::Full;
99
use hyper::server::conn::Http;
1010
use hyper::service::service_fn;
11-
use hyper::{Body, Request, Response};
11+
use hyper::{Recv, Request, Response};
1212
use tokio::net::TcpListener;
1313

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

17-
async fn index1(_: Request<Body>) -> Result<Response<Full<Bytes>>, hyper::Error> {
17+
async fn index1(_: Request<Recv>) -> Result<Response<Full<Bytes>>, hyper::Error> {
1818
Ok(Response::new(Full::new(Bytes::from(INDEX1))))
1919
}
2020

21-
async fn index2(_: Request<Body>) -> Result<Response<Full<Bytes>>, hyper::Error> {
21+
async fn index2(_: Request<Recv>) -> Result<Response<Full<Bytes>>, hyper::Error> {
2222
Ok(Response::new(Full::new(Bytes::from(INDEX2))))
2323
}
2424

examples/params.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bytes::Bytes;
55
use http_body_util::{combinators::BoxBody, BodyExt, Empty, Full};
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
use std::collections::HashMap;
@@ -19,7 +19,7 @@ static NOTNUMERIC: &[u8] = b"Number field is not numeric";
1919

2020
// Using service_fn, we can turn this function into a `Service`.
2121
async fn param_example(
22-
req: Request<Body>,
22+
req: Request<Recv>,
2323
) -> Result<Response<BoxBody<Bytes, Infallible>>, hyper::Error> {
2424
match (req.method(), req.uri().path()) {
2525
(&Method::GET, "/") | (&Method::GET, "/post") => Ok(Response::new(full(INDEX))),

examples/send_file.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use tokio::net::TcpListener;
88
use bytes::Bytes;
99
use http_body_util::Full;
1010
use hyper::service::service_fn;
11-
use hyper::{Body, Method, Request, Response, Result, StatusCode};
11+
use hyper::{Method, Recv, Request, Response, Result, StatusCode};
1212

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

39-
async fn response_examples(req: Request<Body>) -> Result<Response<Full<Bytes>>> {
39+
async fn response_examples(req: Request<Recv>) -> Result<Response<Full<Bytes>>> {
4040
match (req.method(), req.uri().path()) {
4141
(&Method::GET, "/") | (&Method::GET, "/index.html") => simple_file_send(INDEX).await,
4242
(&Method::GET, "/no_file.html") => {

examples/service_struct_impl.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use bytes::Bytes;
22
use http_body_util::Full;
33
use hyper::server::conn::Http;
44
use hyper::service::Service;
5-
use hyper::{Body, Request, Response};
5+
use hyper::{Recv, Request, Response};
66
use tokio::net::TcpListener;
77

88
use std::future::Future;
@@ -37,7 +37,7 @@ struct Svc {
3737
counter: Counter,
3838
}
3939

40-
impl Service<Request<Body>> for Svc {
40+
impl Service<Request<Recv>> for Svc {
4141
type Response = Response<Full<Bytes>>;
4242
type Error = hyper::Error;
4343
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
@@ -46,7 +46,7 @@ impl Service<Request<Body>> for Svc {
4646
Poll::Ready(Ok(()))
4747
}
4848

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

examples/upgrades.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use hyper::header::{HeaderValue, UPGRADE};
1414
use hyper::server::conn::Http;
1515
use hyper::service::service_fn;
1616
use hyper::upgrade::Upgraded;
17-
use hyper::{Body, Request, Response, StatusCode};
17+
use hyper::{Recv, Request, Response, StatusCode};
1818

1919
// A simple type alias so as to DRY.
2020
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
@@ -38,7 +38,7 @@ async fn server_upgraded_io(mut upgraded: Upgraded) -> Result<()> {
3838
}
3939

4040
/// Our server HTTP handler to initiate HTTP upgrades.
41-
async fn server_upgrade(mut req: Request<Body>) -> Result<Response<Empty<Bytes>>> {
41+
async fn server_upgrade(mut req: Request<Recv>) -> Result<Response<Empty<Bytes>>> {
4242
let mut res = Response::new(Empty::new());
4343

4444
// Send a 400 to any request that doesn't have

examples/web_api.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use bytes::{Buf, Bytes};
66
use http_body_util::{BodyExt, Full};
77
use hyper::server::conn::Http;
88
use hyper::service::service_fn;
9-
use hyper::{header, Body, Method, Request, Response, StatusCode};
9+
use hyper::{header, Method, Recv, Request, Response, StatusCode};
1010
use tokio::net::{TcpListener, TcpStream};
1111

1212
type GenericError = Box<dyn std::error::Error + Send + Sync>;
@@ -46,7 +46,7 @@ async fn client_request_response() -> Result<Response<BoxBody>> {
4646
Ok(Response::new(res_body))
4747
}
4848

49-
async fn api_post_response(req: Request<Body>) -> Result<Response<BoxBody>> {
49+
async fn api_post_response(req: Request<Recv>) -> Result<Response<BoxBody>> {
5050
// Aggregate the body...
5151
let whole_body = hyper::body::aggregate(req).await?;
5252
// Decode as JSON...
@@ -77,7 +77,7 @@ async fn api_get_response() -> Result<Response<BoxBody>> {
7777
Ok(res)
7878
}
7979

80-
async fn response_examples(req: Request<Body>) -> Result<Response<BoxBody>> {
80+
async fn response_examples(req: Request<Recv>) -> Result<Response<BoxBody>> {
8181
match (req.method(), req.uri().path()) {
8282
(&Method::GET, "/") | (&Method::GET, "/index.html") => Ok(Response::new(full(INDEX))),
8383
(&Method::GET, "/test.html") => client_request_response().await,

src/body/body.rs

+28-28
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type TrailersSender = oneshot::Sender<HeaderMap>;
2424
/// Note: To read the full body, use [`body::to_bytes`](crate::body::to_bytes)
2525
/// or [`body::aggregate`](crate::body::aggregate).
2626
#[must_use = "streams do nothing unless polled"]
27-
pub struct Body {
27+
pub struct Recv {
2828
kind: Kind,
2929
}
3030

@@ -70,16 +70,16 @@ pub struct Sender {
7070
const WANT_PENDING: usize = 1;
7171
const WANT_READY: usize = 2;
7272

73-
impl Body {
73+
impl Recv {
7474
/// Create a `Body` stream with an associated sender half.
7575
///
7676
/// Useful when wanting to stream chunks from another thread.
7777
#[inline]
78-
pub fn channel() -> (Sender, Body) {
78+
pub fn channel() -> (Sender, Recv) {
7979
Self::new_channel(DecodedLength::CHUNKED, /*wanter =*/ false)
8080
}
8181

82-
pub(crate) fn new_channel(content_length: DecodedLength, wanter: bool) -> (Sender, Body) {
82+
pub(crate) fn new_channel(content_length: DecodedLength, wanter: bool) -> (Sender, Recv) {
8383
let (data_tx, data_rx) = mpsc::channel(0);
8484
let (trailers_tx, trailers_rx) = oneshot::channel();
8585

@@ -94,7 +94,7 @@ impl Body {
9494
data_tx,
9595
trailers_tx: Some(trailers_tx),
9696
};
97-
let rx = Body::new(Kind::Chan {
97+
let rx = Recv::new(Kind::Chan {
9898
content_length,
9999
want_tx,
100100
data_rx,
@@ -104,18 +104,18 @@ impl Body {
104104
(tx, rx)
105105
}
106106

107-
fn new(kind: Kind) -> Body {
108-
Body { kind }
107+
fn new(kind: Kind) -> Recv {
108+
Recv { kind }
109109
}
110110

111111
#[allow(dead_code)]
112-
pub(crate) fn empty() -> Body {
113-
Body::new(Kind::Empty)
112+
pub(crate) fn empty() -> Recv {
113+
Recv::new(Kind::Empty)
114114
}
115115

116116
#[cfg(feature = "ffi")]
117-
pub(crate) fn ffi() -> Body {
118-
Body::new(Kind::Ffi(crate::ffi::UserBody::new()))
117+
pub(crate) fn ffi() -> Recv {
118+
Recv::new(Kind::Ffi(crate::ffi::UserBody::new()))
119119
}
120120

121121
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
@@ -129,7 +129,7 @@ impl Body {
129129
if !content_length.is_exact() && recv.is_end_stream() {
130130
content_length = DecodedLength::ZERO;
131131
}
132-
let body = Body::new(Kind::H2 {
132+
let body = Recv::new(Kind::H2 {
133133
ping,
134134
content_length,
135135
recv,
@@ -194,7 +194,7 @@ impl Body {
194194
}
195195
}
196196

197-
impl HttpBody for Body {
197+
impl HttpBody for Recv {
198198
type Data = Bytes;
199199
type Error = crate::Error;
200200

@@ -270,7 +270,7 @@ impl HttpBody for Body {
270270
}
271271
}
272272

273-
impl fmt::Debug for Body {
273+
impl fmt::Debug for Recv {
274274
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
275275
#[derive(Debug)]
276276
struct Streaming;
@@ -382,14 +382,14 @@ mod tests {
382382
use std::mem;
383383
use std::task::Poll;
384384

385-
use super::{Body, DecodedLength, HttpBody, Sender, SizeHint};
385+
use super::{DecodedLength, HttpBody, Recv, Sender, SizeHint};
386386

387387
#[test]
388388
fn test_size_of() {
389389
// These are mostly to help catch *accidentally* increasing
390390
// the size by too much.
391391

392-
let body_size = mem::size_of::<Body>();
392+
let body_size = mem::size_of::<Recv>();
393393
let body_expected_size = mem::size_of::<u64>() * 6;
394394
assert!(
395395
body_size <= body_expected_size,
@@ -398,7 +398,7 @@ mod tests {
398398
body_expected_size,
399399
);
400400

401-
assert_eq!(body_size, mem::size_of::<Option<Body>>(), "Option<Body>");
401+
assert_eq!(body_size, mem::size_of::<Option<Recv>>(), "Option<Body>");
402402

403403
assert_eq!(
404404
mem::size_of::<Sender>(),
@@ -415,18 +415,18 @@ mod tests {
415415

416416
#[test]
417417
fn size_hint() {
418-
fn eq(body: Body, b: SizeHint, note: &str) {
418+
fn eq(body: Recv, b: SizeHint, note: &str) {
419419
let a = body.size_hint();
420420
assert_eq!(a.lower(), b.lower(), "lower for {:?}", note);
421421
assert_eq!(a.upper(), b.upper(), "upper for {:?}", note);
422422
}
423423

424-
eq(Body::empty(), SizeHint::with_exact(0), "empty");
424+
eq(Recv::empty(), SizeHint::with_exact(0), "empty");
425425

426-
eq(Body::channel().1, SizeHint::new(), "channel");
426+
eq(Recv::channel().1, SizeHint::new(), "channel");
427427

428428
eq(
429-
Body::new_channel(DecodedLength::new(4), /*wanter =*/ false).1,
429+
Recv::new_channel(DecodedLength::new(4), /*wanter =*/ false).1,
430430
SizeHint::with_exact(4),
431431
"channel with length",
432432
);
@@ -435,7 +435,7 @@ mod tests {
435435
#[cfg(not(miri))]
436436
#[tokio::test]
437437
async fn channel_abort() {
438-
let (tx, mut rx) = Body::channel();
438+
let (tx, mut rx) = Recv::channel();
439439

440440
tx.abort();
441441

@@ -446,7 +446,7 @@ mod tests {
446446
#[cfg(not(miri))]
447447
#[tokio::test]
448448
async fn channel_abort_when_buffer_is_full() {
449-
let (mut tx, mut rx) = Body::channel();
449+
let (mut tx, mut rx) = Recv::channel();
450450

451451
tx.try_send_data("chunk 1".into()).expect("send 1");
452452
// buffer is full, but can still send abort
@@ -461,7 +461,7 @@ mod tests {
461461

462462
#[test]
463463
fn channel_buffers_one() {
464-
let (mut tx, _rx) = Body::channel();
464+
let (mut tx, _rx) = Recv::channel();
465465

466466
tx.try_send_data("chunk 1".into()).expect("send 1");
467467

@@ -473,14 +473,14 @@ mod tests {
473473
#[cfg(not(miri))]
474474
#[tokio::test]
475475
async fn channel_empty() {
476-
let (_, mut rx) = Body::channel();
476+
let (_, mut rx) = Recv::channel();
477477

478478
assert!(rx.data().await.is_none());
479479
}
480480

481481
#[test]
482482
fn channel_ready() {
483-
let (mut tx, _rx) = Body::new_channel(DecodedLength::CHUNKED, /*wanter = */ false);
483+
let (mut tx, _rx) = Recv::new_channel(DecodedLength::CHUNKED, /*wanter = */ false);
484484

485485
let mut tx_ready = tokio_test::task::spawn(tx.ready());
486486

@@ -489,7 +489,7 @@ mod tests {
489489

490490
#[test]
491491
fn channel_wanter() {
492-
let (mut tx, mut rx) = Body::new_channel(DecodedLength::CHUNKED, /*wanter = */ true);
492+
let (mut tx, mut rx) = Recv::new_channel(DecodedLength::CHUNKED, /*wanter = */ true);
493493

494494
let mut tx_ready = tokio_test::task::spawn(tx.ready());
495495
let mut rx_data = tokio_test::task::spawn(rx.data());
@@ -510,7 +510,7 @@ mod tests {
510510

511511
#[test]
512512
fn channel_notices_closure() {
513-
let (mut tx, rx) = Body::new_channel(DecodedLength::CHUNKED, /*wanter = */ true);
513+
let (mut tx, rx) = Recv::new_channel(DecodedLength::CHUNKED, /*wanter = */ true);
514514

515515
let mut tx_ready = tokio_test::task::spawn(tx.ready());
516516

0 commit comments

Comments
 (0)