Skip to content

Commit dde24f7

Browse files
committed
feat(body): rename Recv to Incoming
The concrete "recv stream" body type is renamed to `Incoming`.
1 parent 0888623 commit dde24f7

29 files changed

+164
-157
lines changed

examples/echo.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ use std::net::SocketAddr;
44

55
use bytes::Bytes;
66
use http_body_util::{combinators::BoxBody, BodyExt, Empty, Full};
7-
use hyper::body::Body as _;
87
use hyper::server::conn::http1;
98
use hyper::service::service_fn;
10-
use hyper::{Method, Recv, Request, Response, StatusCode};
9+
use hyper::{body::Body, Method, Request, Response, StatusCode};
1110
use tokio::net::TcpListener;
1211

1312
/// This is our service handler. It receives a Request, routes on its
1413
/// path, and returns a Future of a Response.
15-
async fn echo(req: Request<Recv>) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
14+
async fn echo(
15+
req: Request<hyper::body::Incoming>,
16+
) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
1617
match (req.method(), req.uri().path()) {
1718
// Serve some instructions at /
1819
(&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::http1;
99
use hyper::service::service_fn;
10-
use hyper::{Recv, Request, Response};
10+
use hyper::{Request, Response};
1111
use tokio::net::TcpListener;
1212

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

examples/http_proxy.rs

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

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

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

46-
async fn proxy(req: Request<Recv>) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
46+
async fn proxy(
47+
req: Request<hyper::body::Incoming>,
48+
) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
4749
println!("req: {:?}", req);
4850

4951
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::http1;
1010
use hyper::service::service_fn;
11-
use hyper::{Recv, Request, Response};
11+
use hyper::{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<Recv>) -> Result<Response<Full<Bytes>>, hyper::Error> {
17+
async fn index1(_: Request<hyper::body::Incoming>) -> Result<Response<Full<Bytes>>, hyper::Error> {
1818
Ok(Response::new(Full::new(Bytes::from(INDEX1))))
1919
}
2020

21-
async fn index2(_: Request<Recv>) -> Result<Response<Full<Bytes>>, hyper::Error> {
21+
async fn index2(_: Request<hyper::body::Incoming>) -> 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::http1;
77
use hyper::service::service_fn;
8-
use hyper::{Method, Recv, Request, Response, StatusCode};
8+
use hyper::{Method, 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<Recv>,
22+
req: Request<hyper::body::Incoming>,
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::{Method, Recv, Request, Response, Result, StatusCode};
11+
use hyper::{Method, 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<Recv>) -> Result<Response<Full<Bytes>>> {
39+
async fn response_examples(req: Request<hyper::body::Incoming>) -> 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::http1;
44
use hyper::service::Service;
5-
use hyper::{Recv, Request, Response};
5+
use hyper::{body::Incoming as IncomingBody, Request, Response};
66
use tokio::net::TcpListener;
77

88
use std::future::Future;
@@ -36,12 +36,12 @@ struct Svc {
3636
counter: Counter,
3737
}
3838

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

44-
fn call(&mut self, req: Request<Recv>) -> Self::Future {
44+
fn call(&mut self, req: Request<IncomingBody>) -> Self::Future {
4545
fn mk_response(s: String) -> Result<Response<Full<Bytes>>, hyper::Error> {
4646
Ok(Response::builder().body(Full::new(Bytes::from(s))).unwrap())
4747
}

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::http1;
1515
use hyper::service::service_fn;
1616
use hyper::upgrade::Upgraded;
17-
use hyper::{Recv, Request, Response, StatusCode};
17+
use hyper::{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<Recv>) -> Result<Response<Empty<Bytes>>> {
41+
async fn server_upgrade(mut req: Request<hyper::body::Incoming>) -> 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::http1;
88
use hyper::service::service_fn;
9-
use hyper::{header, Method, Recv, Request, Response, StatusCode};
9+
use hyper::{body::Incoming as IncomingBody, header, Method, 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<Recv>) -> Result<Response<BoxBody>> {
49+
async fn api_post_response(req: Request<IncomingBody>) -> Result<Response<BoxBody>> {
5050
// Aggregate the body...
5151
let whole_body = req.collect().await?.aggregate();
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<Recv>) -> Result<Response<BoxBody>> {
80+
async fn response_examples(req: Request<IncomingBody>) -> 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 renamed to src/body/incoming.rs

+29-28
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type TrailersSender = oneshot::Sender<HeaderMap>;
1818

1919
/// A stream of `Bytes`, used when receiving bodies from the network.
2020
#[must_use = "streams do nothing unless polled"]
21-
pub struct Recv {
21+
pub struct Incoming {
2222
kind: Kind,
2323
}
2424

@@ -65,17 +65,17 @@ pub(crate) struct Sender {
6565
const WANT_PENDING: usize = 1;
6666
const WANT_READY: usize = 2;
6767

68-
impl Recv {
68+
impl Incoming {
6969
/// Create a `Body` stream with an associated sender half.
7070
///
7171
/// Useful when wanting to stream chunks from another thread.
7272
#[inline]
7373
#[allow(unused)]
74-
pub(crate) fn channel() -> (Sender, Recv) {
74+
pub(crate) fn channel() -> (Sender, Incoming) {
7575
Self::new_channel(DecodedLength::CHUNKED, /*wanter =*/ false)
7676
}
7777

78-
pub(crate) fn new_channel(content_length: DecodedLength, wanter: bool) -> (Sender, Recv) {
78+
pub(crate) fn new_channel(content_length: DecodedLength, wanter: bool) -> (Sender, Incoming) {
7979
let (data_tx, data_rx) = mpsc::channel(0);
8080
let (trailers_tx, trailers_rx) = oneshot::channel();
8181

@@ -90,7 +90,7 @@ impl Recv {
9090
data_tx,
9191
trailers_tx: Some(trailers_tx),
9292
};
93-
let rx = Recv::new(Kind::Chan {
93+
let rx = Incoming::new(Kind::Chan {
9494
content_length,
9595
want_tx,
9696
data_rx,
@@ -100,18 +100,18 @@ impl Recv {
100100
(tx, rx)
101101
}
102102

103-
fn new(kind: Kind) -> Recv {
104-
Recv { kind }
103+
fn new(kind: Kind) -> Incoming {
104+
Incoming { kind }
105105
}
106106

107107
#[allow(dead_code)]
108-
pub(crate) fn empty() -> Recv {
109-
Recv::new(Kind::Empty)
108+
pub(crate) fn empty() -> Incoming {
109+
Incoming::new(Kind::Empty)
110110
}
111111

112112
#[cfg(feature = "ffi")]
113-
pub(crate) fn ffi() -> Recv {
114-
Recv::new(Kind::Ffi(crate::ffi::UserBody::new()))
113+
pub(crate) fn ffi() -> Incoming {
114+
Incoming::new(Kind::Ffi(crate::ffi::UserBody::new()))
115115
}
116116

117117
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
@@ -125,7 +125,7 @@ impl Recv {
125125
if !content_length.is_exact() && recv.is_end_stream() {
126126
content_length = DecodedLength::ZERO;
127127
}
128-
let body = Recv::new(Kind::H2 {
128+
let body = Incoming::new(Kind::H2 {
129129
data_done: false,
130130
ping,
131131
content_length,
@@ -151,7 +151,7 @@ impl Recv {
151151
}
152152
}
153153

154-
impl Body for Recv {
154+
impl Body for Incoming {
155155
type Data = Bytes;
156156
type Error = crate::Error;
157157

@@ -259,7 +259,7 @@ impl Body for Recv {
259259
}
260260
}
261261

262-
impl fmt::Debug for Recv {
262+
impl fmt::Debug for Incoming {
263263
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
264264
#[derive(Debug)]
265265
struct Streaming;
@@ -375,15 +375,15 @@ mod tests {
375375
use std::mem;
376376
use std::task::Poll;
377377

378-
use super::{Body, DecodedLength, Recv, Sender, SizeHint};
378+
use super::{Body, DecodedLength, Incoming, Sender, SizeHint};
379379
use http_body_util::BodyExt;
380380

381381
#[test]
382382
fn test_size_of() {
383383
// These are mostly to help catch *accidentally* increasing
384384
// the size by too much.
385385

386-
let body_size = mem::size_of::<Recv>();
386+
let body_size = mem::size_of::<Incoming>();
387387
let body_expected_size = mem::size_of::<u64>() * 5;
388388
assert!(
389389
body_size <= body_expected_size,
@@ -392,7 +392,7 @@ mod tests {
392392
body_expected_size,
393393
);
394394

395-
//assert_eq!(body_size, mem::size_of::<Option<Recv>>(), "Option<Recv>");
395+
//assert_eq!(body_size, mem::size_of::<Option<Incoming>>(), "Option<Incoming>");
396396

397397
assert_eq!(
398398
mem::size_of::<Sender>(),
@@ -409,18 +409,18 @@ mod tests {
409409

410410
#[test]
411411
fn size_hint() {
412-
fn eq(body: Recv, b: SizeHint, note: &str) {
412+
fn eq(body: Incoming, b: SizeHint, note: &str) {
413413
let a = body.size_hint();
414414
assert_eq!(a.lower(), b.lower(), "lower for {:?}", note);
415415
assert_eq!(a.upper(), b.upper(), "upper for {:?}", note);
416416
}
417417

418-
eq(Recv::empty(), SizeHint::with_exact(0), "empty");
418+
eq(Incoming::empty(), SizeHint::with_exact(0), "empty");
419419

420-
eq(Recv::channel().1, SizeHint::new(), "channel");
420+
eq(Incoming::channel().1, SizeHint::new(), "channel");
421421

422422
eq(
423-
Recv::new_channel(DecodedLength::new(4), /*wanter =*/ false).1,
423+
Incoming::new_channel(DecodedLength::new(4), /*wanter =*/ false).1,
424424
SizeHint::with_exact(4),
425425
"channel with length",
426426
);
@@ -429,7 +429,7 @@ mod tests {
429429
#[cfg(not(miri))]
430430
#[tokio::test]
431431
async fn channel_abort() {
432-
let (tx, mut rx) = Recv::channel();
432+
let (tx, mut rx) = Incoming::channel();
433433

434434
tx.abort();
435435

@@ -440,7 +440,7 @@ mod tests {
440440
#[cfg(all(not(miri), feature = "http1"))]
441441
#[tokio::test]
442442
async fn channel_abort_when_buffer_is_full() {
443-
let (mut tx, mut rx) = Recv::channel();
443+
let (mut tx, mut rx) = Incoming::channel();
444444

445445
tx.try_send_data("chunk 1".into()).expect("send 1");
446446
// buffer is full, but can still send abort
@@ -462,7 +462,7 @@ mod tests {
462462
#[cfg(feature = "http1")]
463463
#[test]
464464
fn channel_buffers_one() {
465-
let (mut tx, _rx) = Recv::channel();
465+
let (mut tx, _rx) = Incoming::channel();
466466

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

@@ -474,14 +474,14 @@ mod tests {
474474
#[cfg(not(miri))]
475475
#[tokio::test]
476476
async fn channel_empty() {
477-
let (_, mut rx) = Recv::channel();
477+
let (_, mut rx) = Incoming::channel();
478478

479479
assert!(rx.frame().await.is_none());
480480
}
481481

482482
#[test]
483483
fn channel_ready() {
484-
let (mut tx, _rx) = Recv::new_channel(DecodedLength::CHUNKED, /*wanter = */ false);
484+
let (mut tx, _rx) = Incoming::new_channel(DecodedLength::CHUNKED, /*wanter = */ false);
485485

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

@@ -490,7 +490,8 @@ mod tests {
490490

491491
#[test]
492492
fn channel_wanter() {
493-
let (mut tx, mut rx) = Recv::new_channel(DecodedLength::CHUNKED, /*wanter = */ true);
493+
let (mut tx, mut rx) =
494+
Incoming::new_channel(DecodedLength::CHUNKED, /*wanter = */ true);
494495

495496
let mut tx_ready = tokio_test::task::spawn(tx.ready());
496497
let mut rx_data = tokio_test::task::spawn(rx.frame());
@@ -511,7 +512,7 @@ mod tests {
511512

512513
#[test]
513514
fn channel_notices_closure() {
514-
let (mut tx, rx) = Recv::new_channel(DecodedLength::CHUNKED, /*wanter = */ true);
515+
let (mut tx, rx) = Incoming::new_channel(DecodedLength::CHUNKED, /*wanter = */ true);
515516

516517
let mut tx_ready = tokio_test::task::spawn(tx.ready());
517518

0 commit comments

Comments
 (0)