diff --git a/axum/CHANGELOG.md b/axum/CHANGELOG.md index 4fa14a1e..917a39b4 100644 --- a/axum/CHANGELOG.md +++ b/axum/CHANGELOG.md @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased - **fixed:** Fix `Allow` missing from routers with middleware +- **added:** Add `KeepAlive::event` for customizing the event sent for SSE keep alive ([#1729]) + +[#1729]: https://github.com/tokio-rs/axum/pull/1729 # 0.6.7 (17. February, 2023) diff --git a/axum/src/response/sse.rs b/axum/src/response/sse.rs index e66411ab..3ae691f8 100644 --- a/axum/src/response/sse.rs +++ b/axum/src/response/sse.rs @@ -409,16 +409,27 @@ impl KeepAlive { /// /// Default is an empty comment. /// - /// /// # Panics /// /// Panics if `text` contains any newline or carriage returns, as they are not allowed in SSE /// comments. - pub fn text(mut self, text: I) -> Self + pub fn text(self, text: I) -> Self where I: AsRef, { - self.event = Event::default().comment(text).finalize(); + self.event(Event::default().comment(text)) + } + + /// Customize the event of the keep-alive message. + /// + /// Default is an empty comment. + /// + /// # Panics + /// + /// Panics if `event` contains any newline or carriage returns, as they are not allowed in SSE + /// comments. + pub fn event(mut self, event: Event) -> Self { + self.event = event.finalize(); self } }