pub struct SseEventParser { /* private fields */ }Expand description
Incremental SSE event parser.
Unlike extract_sse_data_lines, this parser follows event boundaries and
joins multiple data: lines in the same event with \n.
Implementations§
Source§impl SseEventParser
impl SseEventParser
Sourcepub fn push(&mut self, new_bytes: &[u8]) -> Vec<Vec<u8>>
pub fn push(&mut self, new_bytes: &[u8]) -> Vec<Vec<u8>>
Push a transport byte chunk and return completed SSE event payloads.
Sourcepub fn finish(&mut self) -> Vec<Vec<u8>>
pub fn finish(&mut self) -> Vec<Vec<u8>>
Flush any event buffered by data: lines that never saw a terminating
blank line.
Per the SSE spec an event is dispatched on a blank line. If the transport
closes after a final data: {...}\n with no following blank line
(a reverse proxy stripping trailing whitespace, a truncated TLS frame at
connection close, a non-conformant emitter), SseEventParser::push
leaves that event buffered in event_data and it would otherwise be
silently dropped — including the last content/usage chunk, or even the
[DONE] marker if its trailing blank line was lost.
Call this once the byte stream has ended to emit any such trailing event.
Returns an empty Vec when nothing is buffered. Any incomplete line
still in buf (a data: line with no trailing newline) is intentionally
NOT emitted — it is not a complete SSE line.