pub struct Sse { /* private fields */ }Expand description
Builder for a buffered Server-Sent Events response.
Call Sse::into_response to obtain a Response with:
200 OKContent-Type: text/event-streamCache-Control: no-cacheX-Accel-Buffering: no(disables nginx proxy buffering)
§Example
use rust_web_server::sse::Sse;
let response = Sse::new()
.event("open", "")
.data(r#"{"msg":"hello"}"#)
.retry(5000)
.into_response();Implementations§
Source§impl Sse
impl Sse
Sourcepub fn event(self, event_type: &str, data: &str) -> Sse
pub fn event(self, event_type: &str, data: &str) -> Sse
Append a named event with data.
event_type becomes the event: field; data becomes the data: field.
Sourcepub fn data(self, data: &str) -> Sse
pub fn data(self, data: &str) -> Sse
Append a data-only event (no event: type field; clients receive it as
"message").
Sourcepub fn push(self, event: SseEvent) -> Sse
pub fn push(self, event: SseEvent) -> Sse
Append a fully configured SseEvent (id, type, retry, data).
Sourcepub fn retry(self, ms: u32) -> Sse
pub fn retry(self, ms: u32) -> Sse
Append a retry: directive that tells the client how many milliseconds
to wait before reconnecting after the connection is lost.
Sourcepub fn comment(self, text: &str) -> Sse
pub fn comment(self, text: &str) -> Sse
Append an SSE comment line (starts with :). Used as a keep-alive ping
or annotation; browsers ignore comment content.
Sourcepub fn into_response(self) -> Response
pub fn into_response(self) -> Response
Finalise the builder and return a Response with the correct SSE
headers and the accumulated event body.
Auto Trait Implementations§
impl Freeze for Sse
impl RefUnwindSafe for Sse
impl Send for Sse
impl Sync for Sse
impl Unpin for Sse
impl UnsafeUnpin for Sse
impl UnwindSafe for Sse
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more