Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add KeepAlive::event #1729

Merged
merged 4 commits into from Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions axum/CHANGELOG.md
Expand Up @@ -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)

Expand Down
17 changes: 14 additions & 3 deletions axum/src/response/sse.rs
Expand Up @@ -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<I>(mut self, text: I) -> Self
pub fn text<I>(self, text: I) -> Self
where
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
}
}
Expand Down