Add EventStreamHttpResponse for Server-Sent Events.
Review Request #13280 — Created Sept. 20, 2023 and submitted — Latest diff uploaded
can stream events and data to a client by way of the Server-Sent Events
This works by taking a generator or callable that yields dictionaries of
message data following the spec, allowing for app-specified IDs,
text-based payload data, event names, and retry intervals (for
disconnects) to be streamed to the client.
The response class takes charge of serializing this information for the
client, and can also support resuming of streamed events by intercepting
Last-Event-IDheader and passing it to an event stream
It's important for consumers of this class to be mindful of how it's
used. Browsers have a limit of 6 concurrent HTTP/1.1 requests to the
same domain across all tabs, and a long-running SSE stream will take one
of those slots, potentially starving out other requests. This is far
less of a problem with HTTP/2.
Unit tests pass.
Tested with a makeshift
testing that events and all fields were successfully coming in and
processing as per spec.
curland with GZip middleware turned on and off.