Skip to content

Commit

Permalink
feat(server): remove server::conn::{Http, Connection} types
Browse files Browse the repository at this point in the history
The connection types have been split into version-specific types, in the
`server::conn::{http1, http2}` modules.

BREAKING CHANGE: Either choose a version-specific `Connection` type, or
  look for the auto-version type in `hyper-util`.
  • Loading branch information
seanmonstar committed Oct 17, 2022
1 parent fc4d335 commit 742e4e7
Show file tree
Hide file tree
Showing 22 changed files with 159 additions and 1,260 deletions.
4 changes: 2 additions & 2 deletions benches/pipeline.rs
Expand Up @@ -14,7 +14,7 @@ use http_body_util::Full;
use tokio::net::TcpListener;
use tokio::sync::oneshot;

use hyper::server::conn::Http;
use hyper::server::conn::http1;
use hyper::service::service_fn;
use hyper::Response;

Expand All @@ -41,7 +41,7 @@ fn hello_world_16(b: &mut test::Bencher) {
loop {
let (stream, _addr) = listener.accept().await.expect("accept");

Http::new()
http1::Builder::new()
.pipeline_flush(true)
.serve_connection(
stream,
Expand Down
4 changes: 2 additions & 2 deletions benches/server.rs
Expand Up @@ -13,7 +13,7 @@ use futures_util::{stream, StreamExt};
use http_body_util::{BodyExt, Full, StreamBody};
use tokio::sync::oneshot;

use hyper::server::conn::Http;
use hyper::server::conn::http1;
use hyper::service::service_fn;
use hyper::Response;

Expand All @@ -38,7 +38,7 @@ macro_rules! bench_server {
loop {
let (stream, _) = listener.accept().await.expect("accept");

Http::new()
http1::Builder::new()
.serve_connection(
stream,
service_fn(|_| async {
Expand Down
7 changes: 5 additions & 2 deletions examples/echo.rs
Expand Up @@ -5,7 +5,7 @@ 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::Http;
use hyper::server::conn::http1;
use hyper::service::service_fn;
use hyper::{Method, Recv, Request, Response, StatusCode};
use tokio::net::TcpListener;
Expand Down Expand Up @@ -87,7 +87,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let (stream, _) = listener.accept().await?;

tokio::task::spawn(async move {
if let Err(err) = Http::new().serve_connection(stream, service_fn(echo)).await {
if let Err(err) = http1::Builder::new()
.serve_connection(stream, service_fn(echo))
.await
{
println!("Error serving connection: {:?}", err);
}
});
Expand Down
7 changes: 5 additions & 2 deletions examples/gateway.rs
@@ -1,6 +1,6 @@
#![deny(warnings)]

use hyper::{server::conn::Http, service::service_fn};
use hyper::{server::conn::http1, service::service_fn};
use std::net::SocketAddr;
use tokio::net::{TcpListener, TcpStream};

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

tokio::task::spawn(async move {
if let Err(err) = Http::new().serve_connection(stream, service).await {
if let Err(err) = http1::Builder::new()
.serve_connection(stream, service)
.await
{
println!("Failed to servce connection: {:?}", err);
}
});
Expand Down
4 changes: 2 additions & 2 deletions examples/hello.rs
Expand Up @@ -5,7 +5,7 @@ use std::net::SocketAddr;

use bytes::Bytes;
use http_body_util::Full;
use hyper::server::conn::Http;
use hyper::server::conn::http1;
use hyper::service::service_fn;
use hyper::{Recv, Request, Response};
use tokio::net::TcpListener;
Expand All @@ -26,7 +26,7 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let (stream, _) = listener.accept().await?;

tokio::task::spawn(async move {
if let Err(err) = Http::new()
if let Err(err) = http1::Builder::new()
.serve_connection(stream, service_fn(hello))
.await
{
Expand Down
4 changes: 2 additions & 2 deletions examples/http_proxy.rs
Expand Up @@ -5,7 +5,7 @@ use std::net::SocketAddr;
use bytes::Bytes;
use http_body_util::{combinators::BoxBody, BodyExt, Empty, Full};
use hyper::client::conn::http1::Builder;
use hyper::server::conn::Http;
use hyper::server::conn::http1;
use hyper::service::service_fn;
use hyper::upgrade::Upgraded;
use hyper::{Method, Recv, Request, Response};
Expand All @@ -30,7 +30,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (stream, _) = listener.accept().await?;

tokio::task::spawn(async move {
if let Err(err) = Http::new()
if let Err(err) = http1::Builder::new()
.http1_preserve_header_case(true)
.http1_title_case_headers(true)
.serve_connection(stream, service_fn(proxy))
Expand Down
6 changes: 3 additions & 3 deletions examples/multi_server.rs
Expand Up @@ -6,7 +6,7 @@ use std::net::SocketAddr;
use bytes::Bytes;
use futures_util::future::join;
use http_body_util::Full;
use hyper::server::conn::Http;
use hyper::server::conn::http1;
use hyper::service::service_fn;
use hyper::{Recv, Request, Response};
use tokio::net::TcpListener;
Expand Down Expand Up @@ -35,7 +35,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let (stream, _) = listener.accept().await.unwrap();

tokio::task::spawn(async move {
if let Err(err) = Http::new()
if let Err(err) = http1::Builder::new()
.serve_connection(stream, service_fn(index1))
.await
{
Expand All @@ -51,7 +51,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let (stream, _) = listener.accept().await.unwrap();

tokio::task::spawn(async move {
if let Err(err) = Http::new()
if let Err(err) = http1::Builder::new()
.serve_connection(stream, service_fn(index2))
.await
{
Expand Down
4 changes: 2 additions & 2 deletions examples/params.rs
Expand Up @@ -3,7 +3,7 @@

use bytes::Bytes;
use http_body_util::{combinators::BoxBody, BodyExt, Empty, Full};
use hyper::server::conn::Http;
use hyper::server::conn::http1;
use hyper::service::service_fn;
use hyper::{Method, Recv, Request, Response, StatusCode};
use tokio::net::TcpListener;
Expand Down Expand Up @@ -126,7 +126,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let (stream, _) = listener.accept().await?;

tokio::task::spawn(async move {
if let Err(err) = Http::new()
if let Err(err) = http1::Builder::new()
.serve_connection(stream, service_fn(param_example))
.await
{
Expand Down
4 changes: 2 additions & 2 deletions examples/send_file.rs
Expand Up @@ -2,7 +2,7 @@

use std::net::SocketAddr;

use hyper::server::conn::Http;
use hyper::server::conn::http1;
use tokio::net::TcpListener;

use bytes::Bytes;
Expand All @@ -26,7 +26,7 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
let (stream, _) = listener.accept().await?;

tokio::task::spawn(async move {
if let Err(err) = Http::new()
if let Err(err) = http1::Builder::new()
.serve_connection(stream, service_fn(response_examples))
.await
{
Expand Down
4 changes: 2 additions & 2 deletions examples/service_struct_impl.rs
@@ -1,6 +1,6 @@
use bytes::Bytes;
use http_body_util::Full;
use hyper::server::conn::Http;
use hyper::server::conn::http1;
use hyper::service::Service;
use hyper::{Recv, Request, Response};
use tokio::net::TcpListener;
Expand All @@ -22,7 +22,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let (stream, _) = listener.accept().await?;

tokio::task::spawn(async move {
if let Err(err) = Http::new()
if let Err(err) = http1::Builder::new()
.serve_connection(stream, Svc { counter: 81818 })
.await
{
Expand Down
7 changes: 4 additions & 3 deletions examples/single_threaded.rs
@@ -1,6 +1,6 @@
#![deny(warnings)]

use hyper::server::conn::Http;
use hyper::server::conn::http2;
use std::cell::Cell;
use std::net::SocketAddr;
use std::rc::Rc;
Expand Down Expand Up @@ -84,8 +84,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
});

tokio::task::spawn_local(async move {
if let Err(err) = Http::new()
.with_executor(LocalExec)
if let Err(err) = http2::Builder::new(LocalExec)
.serve_connection(stream, service)
.await
{
Expand All @@ -95,6 +94,8 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
}
}

// NOTE: This part is only needed for HTTP/2. HTTP/1 doesn't need an executor.
//
// Since the Server needs to spawn some background tasks, we needed
// to configure an Executor that can spawn !Send futures...
#[derive(Clone, Copy, Debug)]
Expand Down
7 changes: 5 additions & 2 deletions examples/state.rs
Expand Up @@ -8,7 +8,7 @@ use std::sync::{

use bytes::Bytes;
use http_body_util::Full;
use hyper::{server::conn::Http, service::service_fn};
use hyper::{server::conn::http1, service::service_fn};
use hyper::{Error, Response};
use tokio::net::TcpListener;

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

if let Err(err) = Http::new().serve_connection(stream, service).await {
if let Err(err) = http1::Builder::new()
.serve_connection(stream, service)
.await
{
println!("Error serving connection: {:?}", err);
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/upgrades.rs
Expand Up @@ -11,7 +11,7 @@ use tokio::sync::watch;
use bytes::Bytes;
use http_body_util::Empty;
use hyper::header::{HeaderValue, UPGRADE};
use hyper::server::conn::Http;
use hyper::server::conn::http1;
use hyper::service::service_fn;
use hyper::upgrade::Upgraded;
use hyper::{Recv, Request, Response, StatusCode};
Expand Down Expand Up @@ -149,7 +149,7 @@ async fn main() {

let mut rx = rx.clone();
tokio::task::spawn(async move {
let conn = Http::new().serve_connection(stream, service_fn(server_upgrade));
let conn = http1::Builder::new().serve_connection(stream, service_fn(server_upgrade));

// Don't forget to enable upgrades on the connection.
let mut conn = conn.with_upgrades();
Expand Down
7 changes: 5 additions & 2 deletions examples/web_api.rs
Expand Up @@ -4,7 +4,7 @@ use std::net::SocketAddr;

use bytes::{Buf, Bytes};
use http_body_util::{BodyExt, Full};
use hyper::server::conn::Http;
use hyper::server::conn::http1;
use hyper::service::service_fn;
use hyper::{header, Method, Recv, Request, Response, StatusCode};
use tokio::net::{TcpListener, TcpStream};
Expand Down Expand Up @@ -113,7 +113,10 @@ async fn main() -> Result<()> {
tokio::task::spawn(async move {
let service = service_fn(move |req| response_examples(req));

if let Err(err) = Http::new().serve_connection(stream, service).await {
if let Err(err) = http1::Builder::new()
.serve_connection(stream, service)
.await
{
println!("Failed to serve connection: {:?}", err);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/common/exec.rs
Expand Up @@ -20,7 +20,7 @@ pub(crate) type BoxSendFuture = Pin<Box<dyn Future<Output = ()> + Send>>;
// TODO: with the `runtime`feature, `Exec::Default` used `tokio::spawn`. With the
// removal of the opt-in default runtime, this should be refactored.
#[derive(Clone)]
pub enum Exec {
pub(crate) enum Exec {
Default,
Executor(Arc<dyn Executor<BoxSendFuture> + Send + Sync>),
}
Expand Down
4 changes: 2 additions & 2 deletions src/common/io/rewind.rs
Expand Up @@ -14,7 +14,7 @@ pub(crate) struct Rewind<T> {
}

impl<T> Rewind<T> {
#[cfg(any(all(feature = "http2", feature = "server"), test))]
#[cfg(test)]
pub(crate) fn new(io: T) -> Self {
Rewind {
pre: None,
Expand All @@ -29,7 +29,7 @@ impl<T> Rewind<T> {
}
}

#[cfg(any(all(feature = "http1", feature = "http2", feature = "server"), test))]
#[cfg(test)]
pub(crate) fn rewind(&mut self, bs: Bytes) {
debug_assert!(self.pre.is_none());
self.pre = Some(bs);
Expand Down

0 comments on commit 742e4e7

Please sign in to comment.