From 221ef3795b154d8b0d094be5a8a5468773592a74 Mon Sep 17 00:00:00 2001 From: Loic Hausammann Date: Tue, 16 Sep 2025 17:54:44 +0200 Subject: [PATCH] websocket: add a wrapper around is_terminated (#3443) Co-authored-by: Loic Co-authored-by: loikki <851651-loikki@users.noreply.gitlab.com> --- axum/src/extract/ws.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/axum/src/extract/ws.rs b/axum/src/extract/ws.rs index 5ac3f622..4e23273a 100644 --- a/axum/src/extract/ws.rs +++ b/axum/src/extract/ws.rs @@ -96,7 +96,7 @@ use crate::{body::Bytes, response::Response, Error}; use axum_core::body::Body; use futures_util::{ sink::{Sink, SinkExt}, - stream::{Stream, StreamExt}, + stream::{FusedStream, Stream, StreamExt}, }; use http::{ header::{self, HeaderMap, HeaderName, HeaderValue}, @@ -533,6 +533,13 @@ impl WebSocket { } } +impl FusedStream for WebSocket { + /// Returns true if the websocket has been terminated. + fn is_terminated(&self) -> bool { + self.inner.is_terminated() + } +} + impl Stream for WebSocket { type Item = Result;