tide_compressed_sse/lib.rs
1//! Async Server Sent Event parser and encoder.
2//!
3//! # Example
4//!
5//! ```norun
6//! use tide::Request;
7//!
8//! #[async_std::main]
9//! async fn main() -> http_types::Result<()> {
10//! let mut app = tide::new();
11//!
12//! app.at("/sse").get(|req| async move {
13//! let mut res = tide_compressed_sse::upgrade(req, |_req: Request<()>, sender| async move {
14//! sender.send("message", "foo", None).await?;
15//!
16//! Ok(())
17//! });
18//!
19//! Ok(res)
20//! });
21//!
22//! app.listen("localhost:8080").await?;
23//!
24//! Ok(())
25//! }
26//! ```
27//!
28//! # References
29//!
30//! - [SSE Spec](https://html.spec.whatwg.org/multipage/server-sent-events.html#concept-event-stream-last-event-id)
31//! - [EventSource web platform tests](https://github.com/web-platform-tests/wpt/tree/master/eventsource)
32
33#![deny(missing_debug_implementations, nonstandard_style)]
34#![warn(missing_docs, rust_2018_idioms)]
35
36mod decoder;
37mod encoder;
38mod event;
39mod handshake;
40mod lines;
41mod message;
42mod tide;
43
44use encoder::encode;
45use event::Event;
46use message::Message;
47pub use crate::tide::upgrade::upgrade;
48pub use crate::tide::Sender;
49
50/// Exports for tests
51#[cfg(feature = "__internal_test")]
52pub mod internals {
53 pub use crate::decoder::{decode, Decoder};
54 pub use crate::encoder::{encode, Encoder};
55 pub use crate::event::Event;
56}
57
58pub(crate) use lines::Lines;