Skip to content

Rename body to recv temporarily #2965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benches/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tokio::sync::oneshot;

use hyper::server::conn::Http;
use hyper::service::service_fn;
use hyper::{Body, Response};
use hyper::{Recv, Response};

const PIPELINED_REQUESTS: usize = 16;

Expand Down Expand Up @@ -43,7 +43,7 @@ fn hello_world_16(b: &mut test::Bencher) {
.serve_connection(
stream,
service_fn(|_| async {
Ok::<_, hyper::Error>(Response::new(Body::from("Hello, World!")))
Ok::<_, hyper::Error>(Response::new(Recv::from("Hello, World!")))
}),
)
.await
Expand Down
2 changes: 1 addition & 1 deletion benches/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ macro_rules! bench_server {
}};
}

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

Expand Down
6 changes: 3 additions & 3 deletions examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![warn(rust_2018_idioms)]
use std::env;

use hyper::{body::HttpBody as _, Body, Request};
use hyper::{body::HttpBody as _, Recv, Request};
use tokio::io::{self, AsyncWriteExt as _};
use tokio::net::TcpStream;

Expand Down Expand Up @@ -39,7 +39,7 @@ async fn fetch_url(url: hyper::Uri) -> Result<()> {
let addr = format!("{}:{}", host, port);
let stream = TcpStream::connect(addr).await?;

let (mut sender, conn) = hyper::client::conn::handshake(stream).await?;
let (mut sender, conn) = hyper::client::conn::http1::handshake(stream).await?;
tokio::task::spawn(async move {
if let Err(err) = conn.await {
println!("Connection failed: {:?}", err);
Expand All @@ -51,7 +51,7 @@ async fn fetch_url(url: hyper::Uri) -> Result<()> {
let req = Request::builder()
.uri(url)
.header(hyper::header::HOST, authority.as_str())
.body(Body::empty())?;
.body(Recv::empty())?;

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

Expand Down
6 changes: 3 additions & 3 deletions examples/client_json.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![deny(warnings)]
#![warn(rust_2018_idioms)]

use hyper::Body;
use hyper::Recv;
use hyper::{body::Buf, Request};
use serde::Deserialize;
use tokio::net::TcpStream;
Expand Down Expand Up @@ -29,7 +29,7 @@ async fn fetch_json(url: hyper::Uri) -> Result<Vec<User>> {

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

let (mut sender, conn) = hyper::client::conn::handshake(stream).await?;
let (mut sender, conn) = hyper::client::conn::http1::handshake(stream).await?;
tokio::task::spawn(async move {
if let Err(err) = conn.await {
println!("Connection failed: {:?}", err);
Expand All @@ -42,7 +42,7 @@ async fn fetch_json(url: hyper::Uri) -> Result<Vec<User>> {
let req = Request::builder()
.uri(url)
.header(hyper::header::HOST, authority.as_str())
.body(Body::empty())?;
.body(Recv::empty())?;

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

Expand Down
10 changes: 5 additions & 5 deletions examples/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ use std::net::SocketAddr;
use hyper::body::HttpBody as _;
use hyper::server::conn::Http;
use hyper::service::service_fn;
use hyper::{Body, Method, Request, Response, StatusCode};
use hyper::{Method, Recv, Request, Response, StatusCode};
use tokio::net::TcpListener;

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

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

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

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

// Return the 404 Not Found for other routes.
Expand Down
3 changes: 2 additions & 1 deletion examples/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
async move {
let client_stream = TcpStream::connect(addr).await.unwrap();

let (mut sender, conn) = hyper::client::conn::handshake(client_stream).await?;
let (mut sender, conn) =
hyper::client::conn::http1::handshake(client_stream).await?;
tokio::task::spawn(async move {
if let Err(err) = conn.await {
println!("Connection failed: {:?}", err);
Expand Down
6 changes: 3 additions & 3 deletions examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use std::net::SocketAddr;

use hyper::server::conn::Http;
use hyper::service::service_fn;
use hyper::{Body, Request, Response};
use hyper::{Recv, Request, Response};
use tokio::net::TcpListener;

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

#[tokio::main]
Expand Down
10 changes: 5 additions & 5 deletions examples/http_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

use std::net::SocketAddr;

use hyper::client::conn::Builder;
use hyper::client::conn::http1::Builder;
use hyper::server::conn::Http;
use hyper::service::service_fn;
use hyper::upgrade::Upgraded;
use hyper::{Body, Method, Request, Response};
use hyper::{Method, Recv, Request, Response};

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

Expand Down Expand Up @@ -41,7 +41,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}

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

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

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

Ok(resp)
Expand Down
10 changes: 5 additions & 5 deletions examples/multi_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ use std::net::SocketAddr;
use futures_util::future::join;
use hyper::server::conn::Http;
use hyper::service::service_fn;
use hyper::{Body, Request, Response};
use hyper::{Recv, Request, Response};
use tokio::net::TcpListener;

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

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

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

#[tokio::main]
Expand Down
6 changes: 3 additions & 3 deletions examples/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use hyper::server::conn::Http;
use hyper::service::service_fn;
use hyper::{Body, Method, Request, Response, StatusCode};
use hyper::{Method, Recv, Request, Response, StatusCode};
use tokio::net::TcpListener;

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

// Using service_fn, we can turn this function into a `Service`.
async fn param_example(req: Request<Body>) -> Result<Response<Body>, hyper::Error> {
async fn param_example(req: Request<Recv>) -> Result<Response<Recv>, hyper::Error> {
match (req.method(), req.uri().path()) {
(&Method::GET, "/") | (&Method::GET, "/post") => Ok(Response::new(INDEX.into())),
(&Method::POST, "/post") => {
Expand Down Expand Up @@ -96,7 +96,7 @@ async fn param_example(req: Request<Body>) -> Result<Response<Body>, hyper::Erro
}
_ => Ok(Response::builder()
.status(StatusCode::NOT_FOUND)
.body(Body::empty())
.body(Recv::empty())
.unwrap()),
}
}
Expand Down
8 changes: 4 additions & 4 deletions examples/send_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use hyper::server::conn::Http;
use tokio::net::TcpListener;

use hyper::service::service_fn;
use hyper::{Body, Method, Request, Response, Result, StatusCode};
use hyper::{Method, Recv, Request, Response, Result, StatusCode};

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

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

/// HTTP status code 404
fn not_found() -> Response<Body> {
fn not_found() -> Response<Recv> {
Response::builder()
.status(StatusCode::NOT_FOUND)
.body(NOTFOUND.into())
.unwrap()
}

async fn simple_file_send(filename: &str) -> Result<Response<Body>> {
async fn simple_file_send(filename: &str) -> Result<Response<Recv>> {
if let Ok(contents) = tokio::fs::read(filename).await {
let body = contents.into();
return Ok(Response::new(body));
Expand Down
12 changes: 6 additions & 6 deletions examples/service_struct_impl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use hyper::server::conn::Http;
use hyper::service::Service;
use hyper::{Body, Request, Response};
use hyper::{Recv, Request, Response};
use tokio::net::TcpListener;

use std::future::Future;
Expand Down Expand Up @@ -35,18 +35,18 @@ struct Svc {
counter: Counter,
}

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

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

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

let res = match req.uri().path() {
Expand Down
4 changes: 2 additions & 2 deletions examples/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::{
};

use hyper::{server::conn::Http, service::service_fn};
use hyper::{Body, Error, Response};
use hyper::{Error, Recv, Response};
use tokio::net::TcpListener;

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

if let Err(err) = Http::new().serve_connection(stream, service).await {
Expand Down
12 changes: 6 additions & 6 deletions examples/tower_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@ use std::task::{Context, Poll};
use futures_util::future;
use hyper::server::conn::Http;
use hyper::service::Service;
use hyper::{Body, Request, Response};
use hyper::{Recv, Request, Response};
use tokio::net::TcpListener;

const ROOT: &str = "/";

#[derive(Debug)]
pub struct Svc;

impl Service<Request<Body>> for Svc {
type Response = Response<Body>;
impl Service<Request<Recv>> for Svc {
type Response = Response<Recv>;
type Error = hyper::Error;
type Future = future::Ready<Result<Self::Response, Self::Error>>;

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

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

let uri = req.uri();
if uri.path() != ROOT {
let body = Body::from(Vec::new());
let body = Recv::from(Vec::new());
let rsp = rsp.status(404).body(body).unwrap();
return future::ok(rsp);
}

let body = Body::from(Vec::from(&b"heyo!"[..]));
let body = Recv::from(Vec::from(&b"heyo!"[..]));
let rsp = rsp.status(200).body(body).unwrap();
future::ok(rsp)
}
Expand Down
10 changes: 5 additions & 5 deletions examples/upgrades.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tokio::sync::watch;
use hyper::header::{HeaderValue, UPGRADE};
use hyper::service::service_fn;
use hyper::upgrade::Upgraded;
use hyper::{Body, Request, Response, StatusCode};
use hyper::{Recv, Request, Response, StatusCode};
use std::net::SocketAddr;

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

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

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

let stream = TcpStream::connect(addr).await?;
let (mut sender, conn) = hyper::client::conn::handshake(stream).await?;
let (mut sender, conn) = hyper::client::conn::http1::handshake(stream).await?;

tokio::task::spawn(async move {
if let Err(err) = conn.await {
Expand Down
Loading