From 9580b357635031f3d631303f3afffc2afae77933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janosch=20Gr=C3=A4f?= Date: Mon, 1 Jul 2024 14:56:49 +0200 Subject: [PATCH] feat(client): remove 'static lifetime bound on http1/2 client IO (#3667) --- src/client/conn/http1.rs | 14 +++++++------- src/client/conn/http2.rs | 6 +++--- src/proto/h1/dispatch.rs | 8 ++++---- src/proto/h2/client.rs | 2 +- src/server/conn/http1.rs | 8 +------- 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/client/conn/http1.rs b/src/client/conn/http1.rs index 2e91209861..4ea780610d 100644 --- a/src/client/conn/http1.rs +++ b/src/client/conn/http1.rs @@ -51,7 +51,7 @@ pub struct Parts { #[must_use = "futures do nothing unless polled"] pub struct Connection where - T: Read + Write + 'static, + T: Read + Write, B: Body + 'static, { inner: Dispatcher, @@ -59,7 +59,7 @@ where impl Connection where - T: Read + Write + Unpin + 'static, + T: Read + Write + Unpin, B: Body + 'static, B::Error: Into>, { @@ -124,7 +124,7 @@ pub struct Builder { /// See [`client::conn`](crate::client::conn) for more. pub async fn handshake(io: T) -> crate::Result<(SendRequest, Connection)> where - T: Read + Write + Unpin + 'static, + T: Read + Write + Unpin, B: Body + 'static, B::Data: Send, B::Error: Into>, @@ -247,7 +247,7 @@ impl fmt::Debug for SendRequest { impl Connection where - T: Read + Write + Unpin + Send + 'static, + T: Read + Write + Unpin + Send, B: Body + 'static, B::Error: Into>, { @@ -261,7 +261,7 @@ where impl fmt::Debug for Connection where - T: Read + Write + fmt::Debug + 'static, + T: Read + Write + fmt::Debug, B: Body + 'static, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -271,7 +271,7 @@ where impl Future for Connection where - T: Read + Write + Unpin + 'static, + T: Read + Write + Unpin, B: Body + 'static, B::Data: Send, B::Error: Into>, @@ -509,7 +509,7 @@ impl Builder { io: T, ) -> impl Future, Connection)>> where - T: Read + Write + Unpin + 'static, + T: Read + Write + Unpin, B: Body + 'static, B::Data: Send, B::Error: Into>, diff --git a/src/client/conn/http2.rs b/src/client/conn/http2.rs index df78691901..c7938e303b 100644 --- a/src/client/conn/http2.rs +++ b/src/client/conn/http2.rs @@ -40,7 +40,7 @@ impl Clone for SendRequest { #[must_use = "futures do nothing unless polled"] pub struct Connection where - T: Read + Write + 'static + Unpin, + T: Read + Write + Unpin, B: Body + 'static, E: Http2ClientConnExec + Unpin, B::Error: Into>, @@ -70,7 +70,7 @@ pub async fn handshake( io: T, ) -> crate::Result<(SendRequest, Connection)> where - T: Read + Write + Unpin + 'static, + T: Read + Write + Unpin, B: Body + 'static, B::Data: Send, B::Error: Into>, @@ -432,7 +432,7 @@ where io: T, ) -> impl Future, Connection)>> where - T: Read + Write + Unpin + 'static, + T: Read + Write + Unpin, B: Body + 'static, B::Data: Send, B::Error: Into>, diff --git a/src/proto/h1/dispatch.rs b/src/proto/h1/dispatch.rs index be0a88c1f9..dabcff6be3 100644 --- a/src/proto/h1/dispatch.rs +++ b/src/proto/h1/dispatch.rs @@ -107,10 +107,10 @@ where /// /// This is useful for old-style HTTP upgrades, but ignores /// newer-style upgrade API. - pub(crate) fn poll_without_shutdown(&mut self, cx: &mut Context<'_>) -> Poll> - where - Self: Unpin, - { + pub(crate) fn poll_without_shutdown( + &mut self, + cx: &mut Context<'_>, + ) -> Poll> { Pin::new(self).poll_catch(cx, false).map_ok(|ds| { if let Dispatched::Upgrade(pending) = ds { pending.manual(); diff --git a/src/proto/h2/client.rs b/src/proto/h2/client.rs index 7cb6c6ed5b..6675142118 100644 --- a/src/proto/h2/client.rs +++ b/src/proto/h2/client.rs @@ -137,7 +137,7 @@ pub(crate) async fn handshake( timer: Time, ) -> crate::Result> where - T: Read + Write + Unpin + 'static, + T: Read + Write + Unpin, B: Body + 'static, B::Data: Send + 'static, E: Http2ClientConnExec + Unpin, diff --git a/src/server/conn/http1.rs b/src/server/conn/http1.rs index cf22316296..a1e3325785 100644 --- a/src/server/conn/http1.rs +++ b/src/server/conn/http1.rs @@ -166,7 +166,6 @@ where where S: Unpin, S::Future: Unpin, - B: Unpin, { self.conn.poll_without_shutdown(cx) } @@ -177,12 +176,7 @@ where /// # Error /// /// This errors if the underlying connection protocol is not HTTP/1. - pub fn without_shutdown(self) -> impl Future>> - where - S: Unpin, - S::Future: Unpin, - B: Unpin, - { + pub fn without_shutdown(self) -> impl Future>> { let mut zelf = Some(self); futures_util::future::poll_fn(move |cx| { ready!(zelf.as_mut().unwrap().conn.poll_without_shutdown(cx))?;