mirror of
https://github.com/hyperium/hyper.git
synced 2026-01-25 02:16:14 +00:00
feat(body): rename Recv to Incoming (#3022)
The concrete "recv stream" body type is renamed to `Incoming`. Closes #2971
This commit is contained in:
@@ -4,15 +4,16 @@ use std::net::SocketAddr;
|
||||
|
||||
use bytes::Bytes;
|
||||
use http_body_util::{combinators::BoxBody, BodyExt, Empty, Full};
|
||||
use hyper::body::Body as _;
|
||||
use hyper::server::conn::http1;
|
||||
use hyper::service::service_fn;
|
||||
use hyper::{Method, Recv, Request, Response, StatusCode};
|
||||
use hyper::{body::Body, Method, 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<Recv>) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
|
||||
async fn echo(
|
||||
req: Request<hyper::body::Incoming>,
|
||||
) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
|
||||
match (req.method(), req.uri().path()) {
|
||||
// Serve some instructions at /
|
||||
(&Method::GET, "/") => Ok(Response::new(full(
|
||||
|
||||
@@ -7,10 +7,10 @@ use bytes::Bytes;
|
||||
use http_body_util::Full;
|
||||
use hyper::server::conn::http1;
|
||||
use hyper::service::service_fn;
|
||||
use hyper::{Recv, Request, Response};
|
||||
use hyper::{Request, Response};
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
async fn hello(_: Request<Recv>) -> Result<Response<Full<Bytes>>, Infallible> {
|
||||
async fn hello(_: Request<hyper::body::Incoming>) -> Result<Response<Full<Bytes>>, Infallible> {
|
||||
Ok(Response::new(Full::new(Bytes::from("Hello World!"))))
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use hyper::client::conn::http1::Builder;
|
||||
use hyper::server::conn::http1;
|
||||
use hyper::service::service_fn;
|
||||
use hyper::upgrade::Upgraded;
|
||||
use hyper::{Method, Recv, Request, Response};
|
||||
use hyper::{Method, Request, Response};
|
||||
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
|
||||
@@ -43,7 +43,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
}
|
||||
|
||||
async fn proxy(req: Request<Recv>) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
|
||||
async fn proxy(
|
||||
req: Request<hyper::body::Incoming>,
|
||||
) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
|
||||
println!("req: {:?}", req);
|
||||
|
||||
if Method::CONNECT == req.method() {
|
||||
|
||||
@@ -8,17 +8,17 @@ use futures_util::future::join;
|
||||
use http_body_util::Full;
|
||||
use hyper::server::conn::http1;
|
||||
use hyper::service::service_fn;
|
||||
use hyper::{Recv, Request, Response};
|
||||
use hyper::{Request, Response};
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
static INDEX1: &[u8] = b"The 1st service!";
|
||||
static INDEX2: &[u8] = b"The 2nd service!";
|
||||
|
||||
async fn index1(_: Request<Recv>) -> Result<Response<Full<Bytes>>, hyper::Error> {
|
||||
async fn index1(_: Request<hyper::body::Incoming>) -> Result<Response<Full<Bytes>>, hyper::Error> {
|
||||
Ok(Response::new(Full::new(Bytes::from(INDEX1))))
|
||||
}
|
||||
|
||||
async fn index2(_: Request<Recv>) -> Result<Response<Full<Bytes>>, hyper::Error> {
|
||||
async fn index2(_: Request<hyper::body::Incoming>) -> Result<Response<Full<Bytes>>, hyper::Error> {
|
||||
Ok(Response::new(Full::new(Bytes::from(INDEX2))))
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use bytes::Bytes;
|
||||
use http_body_util::{combinators::BoxBody, BodyExt, Empty, Full};
|
||||
use hyper::server::conn::http1;
|
||||
use hyper::service::service_fn;
|
||||
use hyper::{Method, Recv, Request, Response, StatusCode};
|
||||
use hyper::{Method, Request, Response, StatusCode};
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
use std::collections::HashMap;
|
||||
@@ -19,7 +19,7 @@ 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<Recv>,
|
||||
req: Request<hyper::body::Incoming>,
|
||||
) -> Result<Response<BoxBody<Bytes, Infallible>>, hyper::Error> {
|
||||
match (req.method(), req.uri().path()) {
|
||||
(&Method::GET, "/") | (&Method::GET, "/post") => Ok(Response::new(full(INDEX))),
|
||||
|
||||
@@ -8,7 +8,7 @@ use tokio::net::TcpListener;
|
||||
use bytes::Bytes;
|
||||
use http_body_util::Full;
|
||||
use hyper::service::service_fn;
|
||||
use hyper::{Method, Recv, Request, Response, Result, StatusCode};
|
||||
use hyper::{Method, Request, Response, Result, StatusCode};
|
||||
|
||||
static INDEX: &str = "examples/send_file_index.html";
|
||||
static NOTFOUND: &[u8] = b"Not Found";
|
||||
@@ -36,7 +36,7 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
}
|
||||
|
||||
async fn response_examples(req: Request<Recv>) -> Result<Response<Full<Bytes>>> {
|
||||
async fn response_examples(req: Request<hyper::body::Incoming>) -> Result<Response<Full<Bytes>>> {
|
||||
match (req.method(), req.uri().path()) {
|
||||
(&Method::GET, "/") | (&Method::GET, "/index.html") => simple_file_send(INDEX).await,
|
||||
(&Method::GET, "/no_file.html") => {
|
||||
|
||||
@@ -2,7 +2,7 @@ use bytes::Bytes;
|
||||
use http_body_util::Full;
|
||||
use hyper::server::conn::http1;
|
||||
use hyper::service::Service;
|
||||
use hyper::{Recv, Request, Response};
|
||||
use hyper::{body::Incoming as IncomingBody, Request, Response};
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
use std::future::Future;
|
||||
@@ -36,12 +36,12 @@ struct Svc {
|
||||
counter: Counter,
|
||||
}
|
||||
|
||||
impl Service<Request<Recv>> for Svc {
|
||||
impl Service<Request<IncomingBody>> for Svc {
|
||||
type Response = Response<Full<Bytes>>;
|
||||
type Error = hyper::Error;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
|
||||
|
||||
fn call(&mut self, req: Request<Recv>) -> Self::Future {
|
||||
fn call(&mut self, req: Request<IncomingBody>) -> Self::Future {
|
||||
fn mk_response(s: String) -> Result<Response<Full<Bytes>>, hyper::Error> {
|
||||
Ok(Response::builder().body(Full::new(Bytes::from(s))).unwrap())
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ use hyper::header::{HeaderValue, UPGRADE};
|
||||
use hyper::server::conn::http1;
|
||||
use hyper::service::service_fn;
|
||||
use hyper::upgrade::Upgraded;
|
||||
use hyper::{Recv, Request, Response, StatusCode};
|
||||
use hyper::{Request, Response, StatusCode};
|
||||
|
||||
// A simple type alias so as to DRY.
|
||||
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<()> {
|
||||
}
|
||||
|
||||
/// Our server HTTP handler to initiate HTTP upgrades.
|
||||
async fn server_upgrade(mut req: Request<Recv>) -> Result<Response<Empty<Bytes>>> {
|
||||
async fn server_upgrade(mut req: Request<hyper::body::Incoming>) -> Result<Response<Empty<Bytes>>> {
|
||||
let mut res = Response::new(Empty::new());
|
||||
|
||||
// Send a 400 to any request that doesn't have
|
||||
|
||||
@@ -6,7 +6,7 @@ use bytes::{Buf, Bytes};
|
||||
use http_body_util::{BodyExt, Full};
|
||||
use hyper::server::conn::http1;
|
||||
use hyper::service::service_fn;
|
||||
use hyper::{header, Method, Recv, Request, Response, StatusCode};
|
||||
use hyper::{body::Incoming as IncomingBody, header, Method, Request, Response, StatusCode};
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
|
||||
type GenericError = Box<dyn std::error::Error + Send + Sync>;
|
||||
@@ -46,7 +46,7 @@ async fn client_request_response() -> Result<Response<BoxBody>> {
|
||||
Ok(Response::new(res_body))
|
||||
}
|
||||
|
||||
async fn api_post_response(req: Request<Recv>) -> Result<Response<BoxBody>> {
|
||||
async fn api_post_response(req: Request<IncomingBody>) -> Result<Response<BoxBody>> {
|
||||
// Aggregate the body...
|
||||
let whole_body = req.collect().await?.aggregate();
|
||||
// Decode as JSON...
|
||||
@@ -77,7 +77,7 @@ async fn api_get_response() -> Result<Response<BoxBody>> {
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
async fn response_examples(req: Request<Recv>) -> Result<Response<BoxBody>> {
|
||||
async fn response_examples(req: Request<IncomingBody>) -> Result<Response<BoxBody>> {
|
||||
match (req.method(), req.uri().path()) {
|
||||
(&Method::GET, "/") | (&Method::GET, "/index.html") => Ok(Response::new(full(INDEX))),
|
||||
(&Method::GET, "/test.html") => client_request_response().await,
|
||||
|
||||
Reference in New Issue
Block a user