Skip to content

Commit 0766d3f

Browse files
authoredOct 17, 2022
feat(server): remove server::conn::{Http, Connection} types (#3013)
The connection types have been split into version-specific types, in the `server::conn::{http1, http2}` modules. Closes #3012 BREAKING CHANGE: Either choose a version-specific `Connection` type, or look for the auto-version type in `hyper-util`.
1 parent fc4d335 commit 0766d3f

22 files changed

+159
-1260
lines changed
 

‎benches/pipeline.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use http_body_util::Full;
1414
use tokio::net::TcpListener;
1515
use tokio::sync::oneshot;
1616

17-
use hyper::server::conn::Http;
17+
use hyper::server::conn::http1;
1818
use hyper::service::service_fn;
1919
use hyper::Response;
2020

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

44-
Http::new()
44+
http1::Builder::new()
4545
.pipeline_flush(true)
4646
.serve_connection(
4747
stream,

‎benches/server.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use futures_util::{stream, StreamExt};
1313
use http_body_util::{BodyExt, Full, StreamBody};
1414
use tokio::sync::oneshot;
1515

16-
use hyper::server::conn::Http;
16+
use hyper::server::conn::http1;
1717
use hyper::service::service_fn;
1818
use hyper::Response;
1919

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

41-
Http::new()
41+
http1::Builder::new()
4242
.serve_connection(
4343
stream,
4444
service_fn(|_| async {

‎examples/echo.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::net::SocketAddr;
55
use bytes::Bytes;
66
use http_body_util::{combinators::BoxBody, BodyExt, Empty, Full};
77
use hyper::body::Body as _;
8-
use hyper::server::conn::Http;
8+
use hyper::server::conn::http1;
99
use hyper::service::service_fn;
1010
use hyper::{Method, Recv, Request, Response, StatusCode};
1111
use tokio::net::TcpListener;
@@ -87,7 +87,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
8787
let (stream, _) = listener.accept().await?;
8888

8989
tokio::task::spawn(async move {
90-
if let Err(err) = Http::new().serve_connection(stream, service_fn(echo)).await {
90+
if let Err(err) = http1::Builder::new()
91+
.serve_connection(stream, service_fn(echo))
92+
.await
93+
{
9194
println!("Error serving connection: {:?}", err);
9295
}
9396
});

‎examples/gateway.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![deny(warnings)]
22

3-
use hyper::{server::conn::Http, service::service_fn};
3+
use hyper::{server::conn::http1, service::service_fn};
44
use std::net::SocketAddr;
55
use tokio::net::{TcpListener, TcpStream};
66

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

5858
tokio::task::spawn(async move {
59-
if let Err(err) = Http::new().serve_connection(stream, service).await {
59+
if let Err(err) = http1::Builder::new()
60+
.serve_connection(stream, service)
61+
.await
62+
{
6063
println!("Failed to servce connection: {:?}", err);
6164
}
6265
});

‎examples/hello.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::net::SocketAddr;
55

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

2828
tokio::task::spawn(async move {
29-
if let Err(err) = Http::new()
29+
if let Err(err) = http1::Builder::new()
3030
.serve_connection(stream, service_fn(hello))
3131
.await
3232
{

‎examples/http_proxy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::net::SocketAddr;
55
use bytes::Bytes;
66
use http_body_util::{combinators::BoxBody, BodyExt, Empty, Full};
77
use hyper::client::conn::http1::Builder;
8-
use hyper::server::conn::Http;
8+
use hyper::server::conn::http1;
99
use hyper::service::service_fn;
1010
use hyper::upgrade::Upgraded;
1111
use hyper::{Method, Recv, Request, Response};
@@ -30,7 +30,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3030
let (stream, _) = listener.accept().await?;
3131

3232
tokio::task::spawn(async move {
33-
if let Err(err) = Http::new()
33+
if let Err(err) = http1::Builder::new()
3434
.http1_preserve_header_case(true)
3535
.http1_title_case_headers(true)
3636
.serve_connection(stream, service_fn(proxy))

‎examples/multi_server.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::net::SocketAddr;
66
use bytes::Bytes;
77
use futures_util::future::join;
88
use http_body_util::Full;
9-
use hyper::server::conn::Http;
9+
use hyper::server::conn::http1;
1010
use hyper::service::service_fn;
1111
use hyper::{Recv, Request, Response};
1212
use tokio::net::TcpListener;
@@ -35,7 +35,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
3535
let (stream, _) = listener.accept().await.unwrap();
3636

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

5353
tokio::task::spawn(async move {
54-
if let Err(err) = Http::new()
54+
if let Err(err) = http1::Builder::new()
5555
.serve_connection(stream, service_fn(index2))
5656
.await
5757
{

‎examples/params.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

128128
tokio::task::spawn(async move {
129-
if let Err(err) = Http::new()
129+
if let Err(err) = http1::Builder::new()
130130
.serve_connection(stream, service_fn(param_example))
131131
.await
132132
{

‎examples/send_file.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::net::SocketAddr;
44

5-
use hyper::server::conn::Http;
5+
use hyper::server::conn::http1;
66
use tokio::net::TcpListener;
77

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

2828
tokio::task::spawn(async move {
29-
if let Err(err) = Http::new()
29+
if let Err(err) = http1::Builder::new()
3030
.serve_connection(stream, service_fn(response_examples))
3131
.await
3232
{

‎examples/service_struct_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bytes::Bytes;
22
use http_body_util::Full;
3-
use hyper::server::conn::Http;
3+
use hyper::server::conn::http1;
44
use hyper::service::Service;
55
use hyper::{Recv, Request, Response};
66
use tokio::net::TcpListener;
@@ -22,7 +22,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
2222
let (stream, _) = listener.accept().await?;
2323

2424
tokio::task::spawn(async move {
25-
if let Err(err) = Http::new()
25+
if let Err(err) = http1::Builder::new()
2626
.serve_connection(stream, Svc { counter: 81818 })
2727
.await
2828
{

‎examples/single_threaded.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![deny(warnings)]
22

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

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

97+
// NOTE: This part is only needed for HTTP/2. HTTP/1 doesn't need an executor.
98+
//
9899
// Since the Server needs to spawn some background tasks, we needed
99100
// to configure an Executor that can spawn !Send futures...
100101
#[derive(Clone, Copy, Debug)]

‎examples/state.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::sync::{
88

99
use bytes::Bytes;
1010
use http_body_util::Full;
11-
use hyper::{server::conn::Http, service::service_fn};
11+
use hyper::{server::conn::http1, service::service_fn};
1212
use hyper::{Error, Response};
1313
use tokio::net::TcpListener;
1414

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

49-
if let Err(err) = Http::new().serve_connection(stream, service).await {
49+
if let Err(err) = http1::Builder::new()
50+
.serve_connection(stream, service)
51+
.await
52+
{
5053
println!("Error serving connection: {:?}", err);
5154
}
5255
}

‎examples/upgrades.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use tokio::sync::watch;
1111
use bytes::Bytes;
1212
use http_body_util::Empty;
1313
use hyper::header::{HeaderValue, UPGRADE};
14-
use hyper::server::conn::Http;
14+
use hyper::server::conn::http1;
1515
use hyper::service::service_fn;
1616
use hyper::upgrade::Upgraded;
1717
use hyper::{Recv, Request, Response, StatusCode};
@@ -149,7 +149,7 @@ async fn main() {
149149

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

154154
// Don't forget to enable upgrades on the connection.
155155
let mut conn = conn.with_upgrades();

‎examples/web_api.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::net::SocketAddr;
44

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

116-
if let Err(err) = Http::new().serve_connection(stream, service).await {
116+
if let Err(err) = http1::Builder::new()
117+
.serve_connection(stream, service)
118+
.await
119+
{
117120
println!("Failed to serve connection: {:?}", err);
118121
}
119122
});

‎src/common/exec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub(crate) type BoxSendFuture = Pin<Box<dyn Future<Output = ()> + Send>>;
2020
// TODO: with the `runtime`feature, `Exec::Default` used `tokio::spawn`. With the
2121
// removal of the opt-in default runtime, this should be refactored.
2222
#[derive(Clone)]
23-
pub enum Exec {
23+
pub(crate) enum Exec {
2424
Default,
2525
Executor(Arc<dyn Executor<BoxSendFuture> + Send + Sync>),
2626
}

‎src/common/io/rewind.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(crate) struct Rewind<T> {
1414
}
1515

1616
impl<T> Rewind<T> {
17-
#[cfg(any(all(feature = "http2", feature = "server"), test))]
17+
#[cfg(test)]
1818
pub(crate) fn new(io: T) -> Self {
1919
Rewind {
2020
pre: None,
@@ -29,7 +29,7 @@ impl<T> Rewind<T> {
2929
}
3030
}
3131

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

‎src/server/conn/http1.rs

+19-52
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
33
use std::error::Error as StdError;
44
use std::fmt;
5-
use std::marker::PhantomData;
65
use std::sync::Arc;
76
use std::time::Duration;
87

98
use bytes::Bytes;
109
use tokio::io::{AsyncRead, AsyncWrite};
1110

1211
use crate::body::{Body, Recv};
13-
use crate::common::exec::{ConnStreamExec, Exec};
1412
use crate::common::{task, Future, Pin, Poll, Unpin};
1513
use crate::{common::time::Time, rt::Timer};
1614
use crate::proto;
@@ -25,21 +23,18 @@ pin_project_lite::pin_project! {
2523
///
2624
/// Polling this future will drive HTTP forward.
2725
#[must_use = "futures do nothing unless polled"]
28-
pub struct Connection<T, S, E>
26+
pub struct Connection<T, S>
2927
where
3028
S: HttpService<Recv>,
3129
{
3230
conn: Option<Http1Dispatcher<T, S::ResBody, S>>,
33-
// can we remove this?
34-
_exec: PhantomData<E>,
3531
}
3632
}
3733

3834

3935
/// A configuration builder for HTTP/1 server connections.
4036
#[derive(Clone, Debug)]
41-
pub struct Builder<E = Exec> {
42-
pub(crate) _exec: E,
37+
pub struct Builder {
4338
pub(crate) timer: Time,
4439
h1_half_close: bool,
4540
h1_keep_alive: bool,
@@ -75,7 +70,7 @@ pub struct Parts<T, S> {
7570

7671
// ===== impl Connection =====
7772

78-
impl<I, S, E> fmt::Debug for Connection<I, S, E>
73+
impl<I, S> fmt::Debug for Connection<I, S>
7974
where
8075
S: HttpService<Recv>,
8176
{
@@ -84,14 +79,13 @@ where
8479
}
8580
}
8681

87-
impl<I, B, S, E> Connection<I, S, E>
82+
impl<I, B, S> Connection<I, S>
8883
where
8984
S: HttpService<Recv, ResBody = B>,
9085
S::Error: Into<Box<dyn StdError + Send + Sync>>,
9186
I: AsyncRead + AsyncWrite + Unpin,
9287
B: Body + 'static,
9388
B::Error: Into<Box<dyn StdError + Send + Sync>>,
94-
E: ConnStreamExec<S::Future, B>,
9589
{
9690
/// Start a graceful shutdown process for this connection.
9791
///
@@ -187,7 +181,7 @@ where
187181
/// Enable this connection to support higher-level HTTP upgrades.
188182
///
189183
/// See [the `upgrade` module](crate::upgrade) for more.
190-
pub fn with_upgrades(self) -> upgrades::UpgradeableConnection<I, S, E>
184+
pub fn with_upgrades(self) -> upgrades::UpgradeableConnection<I, S>
191185
where
192186
I: Send,
193187
{
@@ -196,14 +190,13 @@ where
196190
}
197191

198192

199-
impl<I, B, S, E> Future for Connection<I, S, E>
193+
impl<I, B, S> Future for Connection<I, S>
200194
where
201195
S: HttpService<Recv, ResBody = B>,
202196
S::Error: Into<Box<dyn StdError + Send + Sync>>,
203197
I: AsyncRead + AsyncWrite + Unpin + 'static,
204198
B: Body + 'static,
205199
B::Error: Into<Box<dyn StdError + Send + Sync>>,
206-
E: ConnStreamExec<S::Future, B>,
207200
{
208201
type Output = crate::Result<()>;
209202

@@ -229,13 +222,10 @@ where
229222

230223
// ===== impl Builder =====
231224

232-
impl<E> Builder<E> {
225+
impl Builder {
233226
/// Create a new connection builder.
234-
///
235-
/// This starts with the default options, and an executor.
236-
pub fn new(exec: E) -> Self {
227+
pub fn new() -> Self {
237228
Self {
238-
_exec: exec,
239229
timer: Time::Empty,
240230
h1_half_close: false,
241231
h1_keep_alive: true,
@@ -351,24 +341,6 @@ impl<E> Builder<E> {
351341
self
352342
}
353343

354-
/// Set the executor used to spawn background tasks.
355-
///
356-
/// Default uses implicit default (like `tokio::spawn`).
357-
pub fn with_executor<E2>(self, exec: E2) -> Builder<E2> {
358-
Builder {
359-
_exec: exec,
360-
timer: self.timer,
361-
h1_half_close: self.h1_half_close,
362-
h1_keep_alive: self.h1_keep_alive,
363-
h1_title_case_headers: self.h1_title_case_headers,
364-
h1_preserve_header_case: self.h1_preserve_header_case,
365-
h1_header_read_timeout: self.h1_header_read_timeout,
366-
h1_writev: self.h1_writev,
367-
max_buf_size: self.max_buf_size,
368-
pipeline_flush: self.pipeline_flush,
369-
}
370-
}
371-
372344
/// Set the timer used in background tasks.
373345
pub fn timer<M>(&mut self, timer: M) -> &mut Self
374346
where
@@ -388,7 +360,7 @@ impl<E> Builder<E> {
388360
/// ```
389361
/// # use hyper::{Recv, Request, Response};
390362
/// # use hyper::service::Service;
391-
/// # use hyper::server::conn::Http;
363+
/// # use hyper::server::conn::http1::Builder;
392364
/// # use tokio::io::{AsyncRead, AsyncWrite};
393365
/// # async fn run<I, S>(some_io: I, some_service: S)
394366
/// # where
@@ -397,7 +369,7 @@ impl<E> Builder<E> {
397369
/// # S::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
398370
/// # S::Future: Send,
399371
/// # {
400-
/// let http = Http::new();
372+
/// let http = Builder::new();
401373
/// let conn = http.serve_connection(some_io, some_service);
402374
///
403375
/// if let Err(e) = conn.await {
@@ -406,14 +378,13 @@ impl<E> Builder<E> {
406378
/// # }
407379
/// # fn main() {}
408380
/// ```
409-
pub fn serve_connection<S, I, Bd>(&self, io: I, service: S) -> Connection<I, S, E>
381+
pub fn serve_connection<I, S>(&self, io: I, service: S) -> Connection<I, S>
410382
where
411-
S: HttpService<Recv, ResBody = Bd>,
383+
S: HttpService<Recv>,
412384
S::Error: Into<Box<dyn StdError + Send + Sync>>,
413-
Bd: Body + 'static,
414-
Bd::Error: Into<Box<dyn StdError + Send + Sync>>,
385+
S::ResBody: 'static,
386+
<S::ResBody as Body>::Error: Into<Box<dyn StdError + Send + Sync>>,
415387
I: AsyncRead + AsyncWrite + Unpin,
416-
E: ConnStreamExec<S::Future, Bd>,
417388
{
418389
let mut conn = proto::Conn::new(io);
419390
conn.set_timer(self.timer.clone());
@@ -447,7 +418,6 @@ impl<E> Builder<E> {
447418
let proto = proto::h1::Dispatcher::new(sd, conn);
448419
Connection {
449420
conn: Some(proto),
450-
_exec: PhantomData,
451421
}
452422
}
453423
}
@@ -459,25 +429,23 @@ mod upgrades {
459429

460430
// A future binding a connection with a Service with Upgrade support.
461431
//
462-
// This type is unnameable outside the crate, and so basically just an
463-
// `impl Future`, without requiring Rust 1.26.
432+
// This type is unnameable outside the crate.
464433
#[must_use = "futures do nothing unless polled"]
465434
#[allow(missing_debug_implementations)]
466-
pub struct UpgradeableConnection<T, S, E>
435+
pub struct UpgradeableConnection<T, S>
467436
where
468437
S: HttpService<Recv>,
469438
{
470-
pub(super) inner: Connection<T, S, E>,
439+
pub(super) inner: Connection<T, S>,
471440
}
472441

473-
impl<I, B, S, E> UpgradeableConnection<I, S, E>
442+
impl<I, B, S> UpgradeableConnection<I, S>
474443
where
475444
S: HttpService<Recv, ResBody = B>,
476445
S::Error: Into<Box<dyn StdError + Send + Sync>>,
477446
I: AsyncRead + AsyncWrite + Unpin,
478447
B: Body + 'static,
479448
B::Error: Into<Box<dyn StdError + Send + Sync>>,
480-
E: ConnStreamExec<S::Future, B>,
481449
{
482450
/// Start a graceful shutdown process for this connection.
483451
///
@@ -488,14 +456,13 @@ mod upgrades {
488456
}
489457
}
490458

491-
impl<I, B, S, E> Future for UpgradeableConnection<I, S, E>
459+
impl<I, B, S> Future for UpgradeableConnection<I, S>
492460
where
493461
S: HttpService<Recv, ResBody = B>,
494462
S::Error: Into<Box<dyn StdError + Send + Sync>>,
495463
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
496464
B: Body + 'static,
497465
B::Error: Into<Box<dyn StdError + Send + Sync>>,
498-
E: ConnStreamExec<S::Future, B>,
499466
{
500467
type Output = crate::Result<()>;
501468

‎src/server/conn/http2.rs

-24
Original file line numberDiff line numberDiff line change
@@ -284,30 +284,6 @@ impl<E> Builder<E> {
284284
///
285285
/// This returns a Future that must be polled in order for HTTP to be
286286
/// driven on the connection.
287-
///
288-
/// # Example
289-
///
290-
/// ```
291-
/// # use hyper::{Recv, Request, Response};
292-
/// # use hyper::service::Service;
293-
/// # use hyper::server::conn::Http;
294-
/// # use tokio::io::{AsyncRead, AsyncWrite};
295-
/// # async fn run<I, S>(some_io: I, some_service: S)
296-
/// # where
297-
/// # I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
298-
/// # S: Service<hyper::Request<Recv>, Response=hyper::Response<Recv>> + Send + 'static,
299-
/// # S::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
300-
/// # S::Future: Send,
301-
/// # {
302-
/// let http = Http::new();
303-
/// let conn = http.serve_connection(some_io, some_service);
304-
///
305-
/// if let Err(e) = conn.await {
306-
/// eprintln!("server connection error: {}", e);
307-
/// }
308-
/// # }
309-
/// # fn main() {}
310-
/// ```
311287
pub fn serve_connection<S, I, Bd>(&self, io: I, service: S) -> Connection<I, S, E>
312288
where
313289
S: HttpService<Recv, ResBody = Bd>,

‎src/server/conn/mod.rs

+9-1,045
Large diffs are not rendered by default.

‎tests/client.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,7 @@ mod conn {
18801880
let addr = listener.local_addr().unwrap();
18811881
let (shdn_tx, mut shdn_rx) = tokio::sync::watch::channel(false);
18821882
tokio::task::spawn(async move {
1883-
use hyper::server::conn::Http;
1883+
use hyper::server::conn::http2;
18841884
use hyper::service::service_fn;
18851885

18861886
loop {
@@ -1892,7 +1892,8 @@ mod conn {
18921892

18931893
let mut shdn_rx = shdn_rx.clone();
18941894
tokio::task::spawn(async move {
1895-
let mut conn = Http::new().with_executor(TokioExecutor).http2_only(true).serve_connection(stream, service);
1895+
let mut conn = http2::Builder::new(TokioExecutor)
1896+
.serve_connection(stream, service);
18961897

18971898
tokio::select! {
18981899
res = &mut conn => {
@@ -2093,10 +2094,8 @@ mod conn {
20932094
// Spawn an HTTP2 server that reads the whole body and responds
20942095
tokio::spawn(async move {
20952096
let sock = listener.accept().await.unwrap().0;
2096-
hyper::server::conn::Http::new()
2097-
.with_executor(TokioExecutor)
2098-
.with_timer(TokioTimer)
2099-
.http2_only(true)
2097+
hyper::server::conn::http2::Builder::new(TokioExecutor)
2098+
.timer(TokioTimer)
21002099
.serve_connection(
21012100
sock,
21022101
service_fn(|req| async move {

‎tests/server.rs

+57-87
Large diffs are not rendered by default.

‎tests/support/mod.rs

+23-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::sync::{
88

99
use bytes::Bytes;
1010
use http_body_util::Full;
11-
use hyper::server::conn::Http;
11+
use hyper::server;
1212
use tokio::net::{TcpListener, TcpStream};
1313

1414
use hyper::service::service_fn;
@@ -383,12 +383,17 @@ async fn async_test(cfg: __TestConfig) {
383383
});
384384

385385
tokio::task::spawn(async move {
386-
Http::new()
387-
.with_executor(TokioExecutor)
388-
.http2_only(http2_only)
389-
.serve_connection(stream, service)
390-
.await
391-
.expect("server error");
386+
if http2_only {
387+
server::conn::http2::Builder::new(TokioExecutor)
388+
.serve_connection(stream, service)
389+
.await
390+
.expect("server error");
391+
} else {
392+
server::conn::http1::Builder::new()
393+
.serve_connection(stream, service)
394+
.await
395+
.expect("server error");
396+
}
392397
});
393398
}
394399
});
@@ -560,12 +565,17 @@ async fn naive_proxy(cfg: ProxyConfig) -> (SocketAddr, impl Future<Output = ()>)
560565
}
561566
});
562567

563-
Http::new()
564-
.with_executor(TokioExecutor)
565-
.http2_only(http2_only)
566-
.serve_connection(stream, service)
567-
.await
568-
.unwrap();
568+
if http2_only {
569+
server::conn::http2::Builder::new(TokioExecutor)
570+
.serve_connection(stream, service)
571+
.await
572+
.unwrap();
573+
} else {
574+
server::conn::http1::Builder::new()
575+
.serve_connection(stream, service)
576+
.await
577+
.unwrap();
578+
}
569579
}
570580
});
571581
};

0 commit comments

Comments
 (0)
Please sign in to comment.