From 380ed048998dfe029d383e26ce87f212c02dd6d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20D=27Andre=CC=81a?= Date: Wed, 16 Apr 2025 14:51:39 -0300 Subject: [PATCH 1/2] feat: add `Connection::has_streams()` for http2 server connections --- Cargo.toml | 2 +- src/proto/h2/server.rs | 8 ++++++++ src/server/conn/http2.rs | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c97f581508..d5453f3d01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ tokio = { version = "1", features = ["sync"] } futures-channel = { version = "0.3", optional = true } futures-util = { version = "0.3", default-features = false, optional = true } -h2 = { version = "0.4.2", optional = true } +h2 = { version = "0.4.9", optional = true } http-body-util = { version = "0.1", optional = true } httparse = { version = "1.9", optional = true } httpdate = { version = "1.0", optional = true } diff --git a/src/proto/h2/server.rs b/src/proto/h2/server.rs index a8a20dd68e..bb83b231db 100644 --- a/src/proto/h2/server.rs +++ b/src/proto/h2/server.rs @@ -189,6 +189,14 @@ where } } } + + /// Checks if there are any streams + pub(crate) fn has_streams(&self) -> bool { + match self.state { + State::Handshaking { .. } => false, + State::Serving(ref srv) => srv.conn.has_streams(), + } + } } impl Future for Server diff --git a/src/server/conn/http2.rs b/src/server/conn/http2.rs index e0d61c13a6..4ac344e50b 100644 --- a/src/server/conn/http2.rs +++ b/src/server/conn/http2.rs @@ -78,6 +78,11 @@ where pub fn graceful_shutdown(mut self: Pin<&mut Self>) { self.conn.graceful_shutdown(); } + + /// Checks if there are any streams + pub fn has_streams(&self) -> bool { + self.conn.has_streams() + } } impl Future for Connection From 4eefc0619c544049fc9ec2aee0546adb63fb7097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20D=27Andre=CC=81a?= Date: Wed, 16 Apr 2025 14:52:02 -0300 Subject: [PATCH 2/2] feat: add `Connection::has_handshake_completed()` for http2 server connections --- src/proto/h2/server.rs | 5 +++++ src/server/conn/http2.rs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/proto/h2/server.rs b/src/proto/h2/server.rs index bb83b231db..bc997670b4 100644 --- a/src/proto/h2/server.rs +++ b/src/proto/h2/server.rs @@ -190,6 +190,11 @@ where } } + /// Checks if handshaking has completed + pub(crate) fn has_handshake_completed(&self) -> bool { + matches!(self.state, State::Serving { .. }) + } + /// Checks if there are any streams pub(crate) fn has_streams(&self) -> bool { match self.state { diff --git a/src/server/conn/http2.rs b/src/server/conn/http2.rs index 4ac344e50b..6161aed652 100644 --- a/src/server/conn/http2.rs +++ b/src/server/conn/http2.rs @@ -79,6 +79,11 @@ where self.conn.graceful_shutdown(); } + /// Checks if handshaking has completed + pub fn has_handshake_completed(&self) -> bool { + self.conn.has_handshake_completed() + } + /// Checks if there are any streams pub fn has_streams(&self) -> bool { self.conn.has_streams()