19 std::string
type =
"message";
42 explicit SseParser(
Handler on_event, std::size_t max_event_bytes = std::size_t{16} << 20);
46 void feed(std::string_view chunk);
53 [[nodiscard]] std::optional<std::chrono::milliseconds>
retry()
const {
return retry_; }
56 void process_line(std::string_view line);
60 std::size_t max_event_bytes_;
64 std::string last_event_id_;
65 std::optional<std::chrono::milliseconds> retry_;
66 bool after_cr_ =
false;
67 bool started_ =
false;
68 std::size_t bom_matched_ = 0;
69 bool has_data_ =
false;
Parses a text/event-stream body fed in chunks of any size, as the WHATWG HTML specification defines i...
Definition sse.hpp:34
void feed(std::string_view chunk)
Parses chunk, calling the handler for every event it completes.
std::optional< std::chrono::milliseconds > retry() const
The reconnection time from the last valid retry: field, if any.
Definition sse.hpp:53
SseParser(Handler on_event, std::size_t max_event_bytes=std::size_t{16}<< 20)
std::function< void(const SseEvent &)> Handler
Definition sse.hpp:36
void finish()
The end of the stream. An event without its closing blank line is discarded, as the specification req...
One server-sent event.
Definition sse.hpp:17
std::string type
The event: field, or message when the event has none.
Definition sse.hpp:19
std::string last_event_id
The last id: seen in the stream so far, as the specification defines it.
Definition sse.hpp:23
std::string data
The data: lines joined with newlines.
Definition sse.hpp:21