Skip to content

Commit

Permalink
Document browsers ignoring SSE events without data fields (#1242)
Browse files Browse the repository at this point in the history
* Document browsers ignoring SSE events without data fields

* only add note on `Event::data`
  • Loading branch information
davidpdrsn committed Oct 20, 2022
1 parent 31f9f5d commit e5f7012
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions axum/src/response/sse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,14 @@ impl Event {
///
/// This corresponds to [`MessageEvent`'s data field].
///
/// [`MessageEvent`'s data field]: https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/data
/// Note that events with an empty data field will be ignored by the browser.
///
/// # Panics
///
/// - Panics if `data` contains any carriage returns, as they cannot be transmitted over SSE.
/// - Panics if `data` or `json_data` have already been called.
///
/// [`MessageEvent`'s data field]: https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/data
pub fn data<T>(mut self, data: T) -> Event
where
T: AsRef<str>,
Expand All @@ -202,11 +204,11 @@ impl Event {
///
/// This corresponds to [`MessageEvent`'s data field].
///
/// [`MessageEvent`'s data field]: https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/data
///
/// # Panics
///
/// Panics if `data` or `json_data` have already been called.
///
/// [`MessageEvent`'s data field]: https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/data
#[cfg(feature = "json")]
pub fn json_data<T>(mut self, data: T) -> serde_json::Result<Event>
where
Expand Down

0 comments on commit e5f7012

Please sign in to comment.