Add KeepAlive::event (#1729)

This commit is contained in:
David Pedersen 2023-02-23 14:14:29 +01:00 committed by GitHub
parent 1f224396a2
commit 2cbaa63d9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View file

@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
# Unreleased # Unreleased
- **fixed:** Fix `Allow` missing from routers with middleware - **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) # 0.6.7 (17. February, 2023)

View file

@ -409,16 +409,27 @@ impl KeepAlive {
/// ///
/// Default is an empty comment. /// Default is an empty comment.
/// ///
///
/// # Panics /// # Panics
/// ///
/// Panics if `text` contains any newline or carriage returns, as they are not allowed in SSE /// Panics if `text` contains any newline or carriage returns, as they are not allowed in SSE
/// comments. /// comments.
pub fn text<I>(mut self, text: I) -> Self pub fn text<I>(self, text: I) -> Self
where where
I: AsRef<str>, I: AsRef<str>,
{ {
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 self
} }
} }