From aa696c26d9dcc654aa363bda171b809fb3b35917 Mon Sep 17 00:00:00 2001 From: kiron1 Date: Wed, 22 Nov 2023 06:18:37 +0800 Subject: [PATCH] feat(client): add `http1::Connection` `without_shutdown()` method (#3430) Signed-off-by: Sven Pfennig --- src/client/conn/http1.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/client/conn/http1.rs b/src/client/conn/http1.rs index fb9a41da25..4d1fed3a31 100644 --- a/src/client/conn/http1.rs +++ b/src/client/conn/http1.rs @@ -88,6 +88,17 @@ where pub fn poll_without_shutdown(&mut self, cx: &mut Context<'_>) -> Poll> { self.inner.poll_without_shutdown(cx) } + + /// Prevent shutdown of the underlying IO object at the end of service the request, + /// instead run `into_parts`. This is a convenience wrapper over `poll_without_shutdown`. + pub async fn without_shutdown(self) -> crate::Result> { + let mut conn = Some(self); + futures_util::future::poll_fn(move |cx| -> Poll>> { + ready!(conn.as_mut().unwrap().poll_without_shutdown(cx))?; + Poll::Ready(Ok(conn.take().unwrap().into_parts())) + }) + .await + } } /// A builder to configure an HTTP connection.