Parses a text/event-stream body fed in chunks of any size, as the WHATWG HTML specification defines it.
More...
#include <sse.hpp>
|
| | SseParser (Handler on_event, std::size_t max_event_bytes=std::size_t{16}<< 20) |
| |
| void | feed (std::string_view chunk) |
| | Parses chunk, calling the handler for every event it completes.
|
| |
| void | finish () |
| | The end of the stream. An event without its closing blank line is discarded, as the specification requires.
|
| |
| std::optional< std::chrono::milliseconds > | retry () const |
| | The reconnection time from the last valid retry: field, if any.
|
| |
Parses a text/event-stream body fed in chunks of any size, as the WHATWG HTML specification defines it.
- Note
- Lines may end in CRLF, LF or CR, also split across chunks. A leading byte-order mark, comment lines (
:) and unknown fields are ignored. An event with no data isn't dispatched. Every event type is passed on: a provider dispatches on SseEvent::type and ignores the types it doesn't know, which APIs add without notice (ping, for one).
◆ Handler
◆ SseParser()
| pulsatrix::orch::SseParser::SseParser |
( |
Handler |
on_event, |
|
|
std::size_t |
max_event_bytes = std::size_t{16}<< 20 |
|
) |
| |
|
explicit |
- Parameters
-
| on_event | called for each complete event. |
| max_event_bytes | the largest event (or line) to accept from the server. |
◆ feed()
| void pulsatrix::orch::SseParser::feed |
( |
std::string_view |
chunk | ) |
|
Parses chunk, calling the handler for every event it completes.
- Exceptions
-
| std::length_error | if a line or an event passes max_event_bytes. |
◆ finish()
| void pulsatrix::orch::SseParser::finish |
( |
| ) |
|
The end of the stream. An event without its closing blank line is discarded, as the specification requires.
◆ retry()
| std::optional< std::chrono::milliseconds > pulsatrix::orch::SseParser::retry |
( |
| ) |
const |
|
inline |
The reconnection time from the last valid retry: field, if any.
The documentation for this class was generated from the following file: