pub struct SSE { /* private fields */ }
This is supported on crate feature
sse
only.Expand description
An SSE response.
Example
use futures_util::stream;
use poem::{
handler,
http::StatusCode,
web::sse::{Event, SSE},
Endpoint, Request,
};
#[handler]
fn index() -> SSE {
SSE::new(stream::iter(vec![
Event::message("a"),
Event::message("b"),
Event::message("c"),
]))
}
let mut resp = index.call(Request::default()).await.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
assert_eq!(
resp.take_body().into_string().await.unwrap(),
"data: a\n\ndata: b\n\ndata: c\n\n"
);
Implementations
Trait Implementations
Consume itself and return Response
.
fn with_header<K, V>(self, key: K, value: V) -> WithHeader<Self> where
K: TryInto<HeaderName>,
V: TryInto<HeaderValue>,
Self: Sized,
fn with_header<K, V>(self, key: K, value: V) -> WithHeader<Self> where
K: TryInto<HeaderName>,
V: TryInto<HeaderValue>,
Self: Sized,
Wrap an impl IntoResponse
to add a header. Read more
Wrap an impl IntoResponse
to set a status code. Read more
Auto Trait Implementations
impl !RefUnwindSafe for SSE
impl !UnwindSafe for SSE
Blanket Implementations
Mutably borrows from an owned value. Read more
Consumes this value returns a poem::Result<T>
.
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more